Next line character not recognised when appendText() is used, for a text area under G4P

edited February 2015 in Library Questions

Hey!

        I have created a text area under G4P GUI builder (updated to the latest versions)...But when I append text to display on the text area, the next line character "\n" is not processed and continues to append in the same line...Code is something like this under a button event...

public void acceptLogin_click(GButton source, GEvent event){
mymonitor_textarea.appendText("Test text...\n");
}

But the string is appended immediately and not in the next line...

The output on the textArea when I click the button appears like this

Test text...Test text...Test text...

and not

Test text...
Test text...
Test text...

Any help is appreciated!

Answers

  • Not an ideal solution but this shows how you might work round the problem

    import g4p_controls.*;
    
    GTextArea txa;
    GButton btn;
    
    void setup() {
      size(400, 400);
      txa = new GTextArea(this, 10, 10, 380, 200);
      btn = new GButton(this, 10, height-30, 100, 20, "Append Text");
      btn.addEventHandler(this, "btn_click");
    }
    
    void draw() {
      background(2540);
    }
    
    public void btn_click(GButton source, GEvent event) {
      txa.setText(txa.getText() + "\nText...");
    } 
    
  • @quark, I tried this, the new line problem was fixed, but this rendered the text area to be unscrollable, scroll bars arent working in the textarea even though the scroll is enabled

  • I will fix this in the next version of G4P at the moment there is no work arround. Sorry.

  • The method you suggested is spitting out nullpointer exceptions when I click the scroll bars...So setText(getText()+something) is not good for making something like a real time monitor...

  • Answer ✓

    Sorry about that, the GTextArea control is by far the complex control to code and I know there are some issues with it. I am looking at a complete refactoring of the code for all editable text controls but this is going to take a long time before it becomes available.

  • As a workaround for those who didn't seem to overcome this issue, try this

    try{
    txa.setText(txa.getText() + "\nText...");
    }catch(NullPointerException e){
    txa.setText(txa.getText() + "\nText...");
    }
    

    This sounds dumb, but gets the job done...

Sign In or Register to comment.