Skip to main content

Alignment of label elements

5 replies [Last post]
unscathed
Offline
Joined: 2009-12-06

Good day!

I am new to using LWUIT and I am trying to make a list composed of labels with a text and icon. My problem is how to align the text at the left side and the icon at the right side. I am using BorderLayout. Is there anyway to make this using the Label methods or should I use a different layout?

Would appreciate any help.

Thanks!
/m

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shankar_vn
Offline
Joined: 2009-11-03

Hi,

Label myLbl = new Label(Image.createImage("/smiley.png"));
myLbl .setText("..Something..");
myLbl .setTextPosition(Label.LEFT);

This will add text to the left of label and Icon to its right

If you want to place Icon to the right edge of the screen, then you can pick conatiner with BorderLayout. Add Label at BorderLayout.CENTER and Icon at BorderLayout.East

unscathed
Offline
Joined: 2009-12-06

Thanks shankar_vn! The BorderLayout works well. My next problem now is that there is a space in between the two label. This is causing some problems with my highlighter. Any clues on how to fix this?

shankar_vn
Offline
Joined: 2009-11-03

this should work!

label.getStyle.setPadding(0,0,0,0);
label.getStyle.setMargin(0,0,0,0);

Shankar

danjose
Offline
Joined: 2009-10-14

you can try the SetGap, if you want to align in precisely...

unscathed
Offline
Joined: 2009-12-06

Thanks Shankar and danjose!