Component lookup methods

46 views
Skip to first unread message

State Thirteen

unread,
Nov 13, 2013, 5:01:57 AM11/13/13
to codenameone...@googlegroups.com
Hi,

Is there any methods for the handcoded app to find component after adding it on a form. For example

Label customLabel = new Label();
customLabel.setText(text);
customLabel.putClientProperty("CustomID", "Label1");
form.addComponent(BorderLayout.SOUTH, customLabel);

.........

label=iterateToFindComponent(form,"Label1");


Maybe I missed something, but I found only one way to get access to this component is to iterate through all components on the form looking for specific ClientProperty.
Is there any methods to access components directly or narrow the search down to Layout areas? For example looking for all components in BorderLayout.SOUTH.
Is there any methods to remove components only in specific Layout area like SOUTH? Or maybe I shouldn't concern about performance impact at all?

Shai Almog

unread,
Nov 13, 2013, 1:42:55 PM11/13/13
to codenameone...@googlegroups.com
Hi,
why not:
form.putClientProperty("Label1", customLabel);

This is what we do in the UI builder to prevent recursive search which is really slow.
The alternative is to do a recursive method that just runs over the components in the container and checks their properties/names which would be expensive if you do it often.

State Thirteen

unread,
Nov 13, 2013, 1:45:31 PM11/13/13
to codenameone...@googlegroups.com

Thanks! This is it )
form.putClientProperty("Label1", customLabel);
Reply all
Reply to author
Forward
0 new messages