LWUIT:如何将标签分配给文本字段

发布于 2024-12-19 17:44:48 字数 339 浏览 3 评论 0原文

我想为 TextField 分配一个标签。我使用以下代码,

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

上面的代码未显示 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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏九 2024-12-26 17:44:48

LWUIT javadoc @ Component 的摘录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

因此,您只需将 Label 与此 Component 相关联,现在将它们实际绑定在一起作为感知/视觉上的单个组。

我建议您使用 ComponentGroup 并添加 TextFieldLabel,您也可以将它们设置为一个组。检查链接有关 ComponentGroup 的更多信息

PS: ComponentGroup 可从 LWUIT 1.5 获取。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文