[wxruby-users] Problem centering a label

Christian Schmidt lists at ruby-forum.com
Thu Mar 19 18:49:04 EDT 2009


Hi Alejandro,

you just need one sizer on your panel. Add one spacer 
(sizer.add_stretch_spacer) before and one after your text.

Like so:

    sizer = BoxSizer.new HORIZONTAL
    sizer.add_stretch_spacer
    sizer.add StaticText.new(self, -1, 'asdf'), 0, 1
    sizer.add_stretch_spacer

hth,
Christian.

Alejandro Michelin salomon wrote:
> Hi
> 
> 
> 
> I have frame.
> 
> Inside i want to put a static text as title, centered.
> 
> I use two sizers, one vertical an other horizontal.
> 
> 
> 
> But title is not centered, is put to left.
> 
> 
> 
> My code is :
> 
> 
> 
> require 'wx';
> 
> 
> 
> class TarefasNova < Wx::Panel
> 
>     def initialize(parent)
> 
>         rect = parent.get_client_rect();
> 
> 
> 
>         super( parent, 1011, Wx::Point.new( 0, 0 ),  rect.get_size(),
> SIMPLE_BORDER, "NovaTarefa" );
> 
> 
> 
>         sizer = Wx::BoxSizer.new(Wx::VERTICAL );
> 
>         box   = Wx::BoxSizer.new(Wx::HORIZONTAL);
> 
> 
> 
>         label = Wx::StaticText.new( self, :label => "CADASTRO DE TAREFAS
> (NOVA)", :size => [250,-1] );
> 
> 
> 
>         box.add( label, 1, Wx::ALIGN_CENTER_VERTICAL, 5);
> 
> 
> 
>         sizer.add_item(box, 0, Wx::ALIGN_CENTER|Wx::ALL, 5);
> 
>      end
> 
> end
> 
> 
> 
> How to make my title centered in the panel?
> 
> 
> 
> Alejandro Michelin Salomon
> 
> 
> 
>   _____
> 
> avast! Antivirus <http://www.avast.com> : Outbound message clean.
> 
> 
> Virus Database (VPS): 090319-0, 19/03/2009
> Tested on: 19/03/2009 17:32:59
> avast! - copyright (c) 1988-2009 ALWIL Software.

-- 
Posted via http://www.ruby-forum.com/.


More information about the wxruby-users mailing list