I want to split the screen by 30% and 70% vertically, How can i achieve this with lwuit? I used/tried GridLayout
but it splits the screen equally. Need a example code for this.
Thanks in advance!
I want to split the screen by 30% and 70% vertically, How can i achieve this with lwuit? I used/tried GridLayout
but it splits the screen equally. Need a example code for this.
Thanks in advance!
Create a class which derives Container :
public class split extends Container {
public split(int h)
{
super(); // you can set your layout type here
setPreferredH(h);
}
}
Then add components of this class in your Form :
public class e extends Form {
private Container c1, c2;
private TextField f1,f2;
public e()
{
super("test split");
c1 = new split(30*getPreferredH()/100);
c2 = new split(70*getPreferredH()/100);
f1 = new TextField("ghgjhg");
f2 = new TextField("jkdhuhg");
c1.addComponent(f1);
c2.addComponent(f2);
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
addComponent(c1);
addComponent(c2);
}
}
You can even set a backgroundPainter
to the split class to show visually the splitting.
Both other answers will fail when rotating the screen of a device.
You can take two approaches, use a table layout which supports percentage distribution of layout constraints.
Or create a subclass of
Contaienr
that overrides thecalcPreferredSize
method and returns a dimension of 30 or 70 percent appropriately. Then just add both of them to aBoxLayout
container and use as desired e.g.: