java-melwuitlwuit-textarealwuit-layouts

Split screen proportionally LWUIT


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!


Solution

  • 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 the calcPreferredSize method and returns a dimension of 30 or 70 percent appropriately. Then just add both of them to a BoxLayout container and use as desired e.g.:

    Container c30 = new Container() {
          public Dimension calcPreferredSize() {
              new Dimension(Display.getInstance().getPreferredHeight(), (int)(Display.getInstance().getPreferredWidth() * 0.7));
          }
    };