2013-06-19 28 views
1

我已经创建了LWUIT TextArea。我想减少我的TextArea的字体大小。我用下面的代码:LWUIT TextArea问题

public class TextAreaMidlet extends MIDlet { 

public void startApp() { 
    Display.init(this); 
    Form mForm = new Form("Text Area"); 
    mForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); 
    Button button = new Button("Click here to open new Form"); 
    mForm.addComponent(button); 
    TextArea textArea = new TextArea(); 
    textArea.setEditable(false); 
    textArea.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL)); 
    textArea.setText("The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog"); 
    mForm.addComponent(textArea); 
    mForm.show(); 
} 

public void pauseApp() { 
} 

public void destroyApp(boolean unconditional) { 
} 

但文本区域显示问题,是这样的:

---------------------------------- 
|The quick brown fox    | 
|jumps over the lazy    | 
|dog, The quick brown    | 
|fox jumps over the lazy   | 
|dog, The quick brown fox   | 
|jumps over the lazy dog   | 
---------------------------------- 

我想它正常显示,类似这样的

---------------------------------- 
|The quick brown fox jumps over the| 
|lazy dog, The quick brown fox  | 
|jumps over the lazy dog, The quick| 
|brown fox jumps over the lazy dog | 
---------------------------------- 

我上传图片here

请帮帮我!

+0

如果我们在LWUIT API看,你可以看看你有一些构造,可以帮助你 – neb1

+0

所以你要在文本区域右侧的文本对齐? – Lucifer

+0

哦,是的。如果TextArea设置了Font:Font.SIZE_MEDIUM,它显示正常,但是用Font.SIZE_SMALL,它显示问题 –

回答

0

start方法在MIDP线程中调用,而不是EDT。你应该换你的代码在callSerially调用(初始化后,一切)这样:

public class TextAreaMidlet extends MIDlet implements Runnable { 

public void startApp() { 
    Display.init(this); 
    Display.getInstance().callSerially(this); 
} 

public void run() { 
    Form mForm = new Form("Text Area"); 
    mForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); 
    Button button = new Button("Click here to open new Form"); 
    mForm.addComponent(button); 
    TextArea textArea = new TextArea(); 
    textArea.setEditable(false); 
    textArea.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL)); 
    textArea.setText("The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog"); 
    mForm.addComponent(textArea); 
    mForm.show(); 
} 

由于简化了这整个痛苦的开始(阿里纳斯Codename One)只是调用的EDT,你很少接触到设备线程,迁移的另一个好理由。

+0

谢谢Shai,但它不工作。如果文本区域设置字体:Font.SIZE_MEDIUM,它正常显示,但Font.SIZE_SMALL,它显示的问题 –

+0

我上传图片 –

+0

你需要上传到堆栈溢出。但是,您的具体问题是您使用了getStyle(),这几乎总是做错了。将您的字体设置为getUnselected/Selected style并理想地使用资源编辑器/设计器工具。 –