I had a custom ListCellRendered which had
setUIID("Underline");
focus = new Label("");
focus.setUIID("UnderlineSelected");
and
@Override
public Component getListFocusComponent(List list) {
return focus;
}
so when the List item is selected the visual appearance of that item
changes. I've now changed the code to use a list of Components, as advised,
where each component is generated from:
Container makeComponent(final Product product) {
int h = Display.getInstance().convertToPixels(8, false);
Container c = new Container();
c.setUIID("Underline");
c.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
c.setScrollableY(false);
Label code = new Label();
code.setUIID("BoldLabel");
code.setText(product.getCode());
Label price = new Label();
price.setUIID("BoldLabel");
price.setText("$" + product.getPrice() + "/" + product.getUnit());
Label desc = new Label();
desc.setUIID("MyLabel");
desc.setText(product.getDescription());
Container c1 = new Container();
c1.setLayout(new BorderLayout());
c1.addComponent(BorderLayout.WEST, code);
c1.addComponent(BorderLayout.EAST, price);
c.add(c1);
c.add(desc);
c.setPreferredH(c.getPreferredH() < h ? h : c.getPreferredH());
return c;
}
where these components are added to a form in a loop. The UIID "Underline"
that the container has renders OK. I've changed the Selected and Pressed
styles for the "Underline" selector to be the same as the
"UnderlineSelected" UIID I was originally using in the List implimentation.
My problem is when one of these containers is selected/pressed there is no
change in the visual appearance.
If I make the components buttons, such as:
Container makeComponent(final ProductCategory pc) {
int h = Display.getInstance().convertToPixels(8, false);
Container c = new Container();
c.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
c.setScrollableY(false);
Button b = new Button(pc.getDescription());
b.setUIID("Underline");
b.setPreferredH(b.getPreferredH() < h ? h : b.getPreferredH());
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
CommonContext.INSTANCE.setProductCategory(pc);
GroupForm f = new GroupForm().init();
f.setBackForm(CategoryForm.this);
f.show();
}
});
c.add(b);
return c;
}
this works because the button changes state.
What is the best way to get a state change in a Container which does not
have a button (or has other stuff in addition to a button).
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/169f05d7-bcec-43b4-a9d2-3e3d4d08cab4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.