FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Aligning a Label

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
zane.sims



Joined: 07 Aug 2007
Posts: 40

PostPosted: Fri Nov 27, 2009 6:12 pm    Post subject: Aligning a Label Reply with quote

Hey all,

Would anyone be able to post a small example showing how to align a gtk.Label to the left when adding it to a gtk.Table? I am not sure how to do this, but the default seems to center the label text. Any help would be greatly appreciated.

Thanks in advance,
Zane
_________________
わたしがプログラマだよ!
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sat Nov 28, 2009 6:52 am    Post subject: Reply with quote

You can use gtk.Alignment to align widgets.

Code:
myTable.attachDefaults(Alignment.east(new Label("My Label")), 0, 1, 2, 3);
Back to top
View user's profile Send private message
zane.sims



Joined: 07 Aug 2007
Posts: 40

PostPosted: Sat Nov 28, 2009 8:36 am    Post subject: Reply with quote

Thanks for the quick reply. Your example seems easy enough, but when I try to add three labels like this:

Code:
table.attach(Alignment.west(new Label("Hello World")),0,1,0,1,GtkAttachOptions.SHRINK, GtkAttachOptions.SHRINK, 4, 4);

   table.attach(Alignment.west(new Label("123")),1,2,0,1,GtkAttachOptions.SHRINK, GtkAttachOptions.SHRINK, 4, 4);

   table.attach(Alignment.west(new Label("test")),0,1,1,2,GtkAttachOptions.SHRINK, GtkAttachOptions.SHRINK, 4, 4);


They don't appear to align correctly. Instead the labels still appear to be centered like:

Code:
Hello World      123

    test


Instead I expected:

Code:
Hello World      123

test


Am I doing something wrong?

Thanks much,
Zane
_________________
わたしがプログラマだよ!
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Nov 29, 2009 5:01 am    Post subject: Reply with quote

use GtkAttachOptions.FILL, when using SHRINK the Alignment widget only uses the space it needs to display the Label. and the alignment widget is centered in the cell. By using FILL the Alignment widget fills the cell and aligns the Label to the left within it's self.

Code:
table.attach(Alignment.west(new Label("Hello World")),0,1,0,1,GtkAttachOptions.SHRINK, GtkAttachOptions.SHRINK, 4, 4);
table.attach(Alignment.west(new Label("123")),        1,2,0,1,GtkAttachOptions.SHRINK, GtkAttachOptions.SHRINK, 4, 4);
table.attach(Alignment.west(new Label("test")),       0,1,1,2,GtkAttachOptions.FILL, GtkAttachOptions.SHRINK, 4, 4);
Back to top
View user's profile Send private message
zane.sims



Joined: 07 Aug 2007
Posts: 40

PostPosted: Sun Nov 29, 2009 9:56 am    Post subject: Reply with quote

Thanks very much, this works perfectly!
_________________
わたしがプログラマだよ!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group