Search code examples
javajava-melwuit

Lwuit Create an empty Line between two Containers


I'd like to create an empty line between to containers embedded in my form with BoxLayout Y_Axis.

The following piece only shows "test1 test", but I'd like to have

"test1

test2"

or even more lines..

import com.sun.lwuit.Container;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.layouts.BoxLayout;

public class Bug extends javax.microedition.midlet.MIDlet {




public void startApp() {

    Display.init(this);

    Container mainContainer = new Container();
    Container current = new Container();
    Form f = new Form();
    f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    current.addComponent(new Label("test1"));
    mainContainer.addComponent(current);
    current = new Container();
    current.setPreferredH(40);
    mainContainer.addComponent(current);
    f.addComponent(mainContainer);
    current = new Container();
    current.addComponent(new Label("test2"));
    mainContainer.addComponent(current);

    f.show();
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
} 

Solution

  • You can use style object for setting margin for first label, like this:

    
    Label textLabel = new Label("test1");
    Style style = textLabel.getStyle();
    style.setMargin(Component.BOTTOM,40);
    current.addComponent(textLabel);