Ameer Moaaviah
Ameer Moaaviah

Reputation: 1526

LWUIT: How to assign Label to the Textfield

i want to assign a label to the TextField. I am using the following code

TextField textField = new TextField();
Label label = new Label("Pick a unique username");
textField.setLabelForComponent(label);
textField.setConstraint(TextField.ANY);
form.addComponent(textField);
form.show();

the above code is not showing the associated label for the TextField. How can it be done ?

Upvotes: 0

Views: 829

Answers (1)

Vimal
Vimal

Reputation: 1266

An excerpt of the Component from the LWUIT javadoc @ link

public void setLabelForComponent(Label componentLabel)

Allows us to indicate the label associated with this component thus providing 
visual feedback related for this component e.g. starting the ticker when the 
component receives focus. 

Parameters:    
componentLabel - a label associated with this component

Hence your are just associating a Label with this Component and now actual binding them together as perceived / visually single group.

.

I would recommend you use ComponentGroup with TextField and Label added to it, also you can style them as a group. Check this link for more information on ComponentGroup

PS: ComponentGroup is available from LWUIT 1.5.

Upvotes: 1

Related Questions