2011-07-07 43 views
1

我想在BoxLayout Y_Axis的表格 中嵌入容器之間創建一個空行。Lwuit在兩個容器之間創建一條空行

下一塊只顯示 「測試1測試」,但我想有

「測試1

test2的」

甚至更​​多行..

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) { 
} 
} 
+0

咱們的話說它不同: form.append(「測試」); form.append(「\ n」); form.append(「test2」); 這個LCDUI代碼如何轉換成LWUIT? – Carl

+0

現在修復 - 重要的是不要在窗體上添加布局,而要在mainContainer上添加布局! – Carl

+0

然後正確地做: 'Container curLine = new Container(); \t \t \t \t \t \t curLine.setPreferredH(someFontYouAreUsing.getHeight()); \t \t \t \t \t \t mainContainer.addComponent(curLine);' – Carl

回答

1

您c設置裕量的標籤,像這樣的使用樣式對象:


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

噢,我的,謝謝你 - 我已經手動修改了頁邊距,但是我非常關注「創建新行」,所以我沒有看到它。 – Carl

+0

看起來像我很快回答。 'current = new Container(); \t \t Label textLabel = new Label(「test1」); \t \t Style style = textLabel.getStyle(); \t \t style.setMargin(Component.TOP,40); \t \t current.addComponent(textLabel); \t \t mainContainer。addComponent(電流); \t \t f.addComponent(mainContainer); \t \t current = new Container(); \t \t current.addComponent(new Label(「test2」)); \t \t mainContainer.addComponent(current); ' TOP和BOTTOM都不會做我所需要的 - 如果我不做一些左邊距或右邊距,那麼佈局仍然會並排排列,這也不是「真正的新線條」。 – Carl

+0

是的,它設置了邊距,並且需要在mainContainer上設置佈局,而不是在窗體上! – Carl

0

在容器之間添加new Label("")您可以在標籤中顯示圖像

+0

插入圖像可能不這樣做的正確方法。 'current.addComponent(new Label(「test1」)); \t \t mainContainer.addComponent(current); \t \t current = new Container(); \t \t current.addComponent(new Label(「」)); \t \t current.setPreferredH(40); \t \t mainContainer.addComponent(current); \t \t f.addComponent(mainContainer); \t \t current = new Container(); \t \t current.addComponent(new Label(「test2」)); \t \t mainContainer.addComponent(current);' 不這樣做 - 插入圖像聽起來不對。 – Carl

相關問題