我创建了LWUIT TextArea。我想减少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) {
}
但TextArea显示问题,如下所示:
----------------------------------
|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 :(得分:0)
在MIDP线程中调用start方法而不是EDT。您应该将代码包装在callSerially
调用(init之后的所有内容)中:
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上调用,你很少接触到设备线程,这是迁移的另一个好理由。