Question

how to put 4 button in row, as in the picture:

enter image description here

The distance between the elements should be changed at different resolutions

Was it helpful?

Solution

There are allot of ways to do everything in LWUIT. Its unclear from your image what your exact constraints are, I'm guessing you want the left most button to be left aligned and the right most to be right aligned. You probably also want the two other buttons to be centered.

I would implement this using a GridLayout with nested FlowLayout elements. As such:

Container c = new Container(new GridLayout(1, 4));
addButton(c, new Button("b1"), Component.LEFT);
addButton(c, new Button("b2"), Component.CENTER);
addButton(c, new Button("b3"), Component.CENTER);
addButton(c, new Button("b4"), Component.RIGHT);


private void addButton(Container c, Button b, int align) {
   Container flow = new Container(new FlowLayout(align));
   flow.addComponent(b);
   c.addComponent(flow);
}

OTHER TIPS

Play with setMargin(Component.RIGHT,x) for the first three Buttons. Set the value of x such that the Buttons are equi-partitioned in the row : you must take into account the preferredWidth of the Buttons for that. For the first Button set its margin-left to 0 ( setMargin(Component.LEFT,0) ) , and for the last Button set its right-margin to 0 ( setMargin(Component.RIGHT,0) ).

You should use use BorderLayout and add the container (described in this answer inside south)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top