1

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) {
}
} 
bharath
  • 14,283
  • 16
  • 57
  • 95
Carl
  • 215
  • 1
  • 11
  • Let's phrase it different: form.append("test"); form.append("\n"); form.append("test2"); How can this LCDUI code be translated to LWUIT? – Carl Jul 07 '11 at 13:27
  • Fixed now - important to add the Layout not on the form but on mainContainer! – Carl Jul 08 '11 at 06:28
  • And to do it properly then: `Container curLine = new Container(); curLine.setPreferredH(someFontYouAreUsing.getHeight()); mainContainer.addComponent(curLine);` – Carl Jul 08 '11 at 06:31

2 Answers2

1

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);
Timii
  • 234
  • 4
  • 11
  • Oh my, thank you - I was already modifying Margins manually but I was so focused on "creating a new line" that I didn't see it. – Carl Jul 07 '11 at 12:19
  • Seems like I answered to soon. `current = new Container(); Label textLabel = new Label("test1"); Style style = textLabel.getStyle(); style.setMargin(Component.TOP,40); current.addComponent(textLabel); mainContainer.addComponent(current); f.addComponent(mainContainer); current = new Container(); current.addComponent(new Label("test2")); mainContainer.addComponent(current); ` Neither TOP nor BOTTOM does what I need - the layout still gets arranged side by side, if I don't do some Margin Left or Margin Right which isn't a "true new line", too. – Carl Jul 07 '11 at 12:28
  • Yes, it's set Margin, and it's needed to set the layout on mainContainer, not on the form! – Carl Jul 08 '11 at 06:28
0

add new Label("") between container you can give image in Label

Nirmal- thInk beYond
  • 11,847
  • 8
  • 35
  • 46
  • Inserting an Image is probably not the right way to do it. `current.addComponent(new Label("test1")); mainContainer.addComponent(current); current = new Container(); current.addComponent(new Label(" ")); current.setPreferredH(40); mainContainer.addComponent(current); f.addComponent(mainContainer); current = new Container(); current.addComponent(new Label("test2")); mainContainer.addComponent(current);` Doesn't do it - and inserting an image sounds wrong. – Carl Jul 07 '11 at 12:14