1

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!

Tan Nguyen
  • 97
  • 1
  • 7

1 Answers1

0

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.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thanks Shai, but it not work. If TextArea set Font:Font.SIZE_MEDIUM, it display normally, but with Font.SIZE_SMALL, it display issue – Tan Nguyen Jun 20 '13 at 04:20
  • You need to upload into stack overflow. However, your specific issue is that you used getStyle() which is almost always the wrong thing to do. Set your font to getUnselected/Selected style and ideally use the resource editor/designer tool. – Shai Almog Jun 20 '13 at 08:16
  • 1
    Thanks Shai, I did and it worked. I can't upload image to stackoverflow because i have only 3 reputation. Have nice day, Shai :D – Tan Nguyen Jun 20 '13 at 09:06