Frage

I have created LWUIT TextArea. I want to reduce my TextArea's font size. I have used the code below:

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

But the TextArea display issue, look like this:

 ----------------------------------
|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           |
 ----------------------------------

I want it display normally, like this

 ----------------------------------
|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 |
 ----------------------------------

I uploaded picture here

Please help me!

War es hilfreich?

Lösung

The start method is invoked in the MIDP thread not the EDT. You should wrap your code in a callSerially call (everything after init) as such:

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();
}

As a sidenote Codename One simplified this whole pain start() is just invoked on the EDT and you are rarely exposed to the device threads, another good reason to migrate.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top