View previous topic :: View next topic |
Author |
Message |
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Fri Nov 27, 2009 6:12 pm Post subject: Aligning a Label |
|
|
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 |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sat Nov 28, 2009 6:52 am Post subject: |
|
|
You can use gtk.Alignment to align widgets.
Code: | myTable.attachDefaults(Alignment.east(new Label("My Label")), 0, 1, 2, 3); |
|
|
Back to top |
|
|
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Sat Nov 28, 2009 8:36 am Post subject: |
|
|
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 |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Nov 29, 2009 5:01 am Post subject: |
|
|
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 |
|
|
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Sun Nov 29, 2009 9:56 am Post subject: |
|
|
Thanks very much, this works perfectly! _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
|
|
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
|