1

我创建了 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 |
 ----------------------------------

我在这里上传图片

请帮我!

4

1 回答 1

0

在 MIDP 线程而不是 EDT 中调用 start 方法。您应该将代码包装在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简化了整个痛苦 start() 只是在 EDT 上调用,您很少接触设备线程,这是迁移的另一个好理由。

于 2013-06-19T14:36:16.367 回答