Export to GitHub

lanterna - issue #70

TextArea does not update with invalidate().


Posted on Mar 11, 2013 by Massive Elephant

Hello.

I've got a TextArea that's supposed to update every time a serial communication is received (e.g. from a serial cable). So far, I've tried a lot of things. I'll try summing up the problem:

  • If you update the TextArea with textArea.insertLine(0, "text") from an external method implemented in my Window subclass (called signature is 'private void appendText(String m)'), the line is inserted (tested with System.out.println(textArea.getLine(0))) but not redrawn on the TextArea itself.

  • If you then try to update the TextArea by calling getOwner().invalidate() nothing happens. I've made some modifications in a custom version of Lanterna, making repaint() and update() public methods and tried calling them - nothing. All three of these methods have been called as both "out of event thread" and in event thread, e.g.:

getOwner().runInEventThread(new Action() { @Override public void doAction() { appendText("Hello"); getOwner().invalidate(); } });

  • Now, this is where it gets weird... If I implement a button in my window and associate it with a doAction() method that calls just the appendText("Hello") it runs fine and updates accordingly.

I've done a lot of debugging and I cannot for the life of me figure out why the button has the ability to update my TextArea with my method, but other methods in my class cannot. I've tried a lot of things, but none of them work.

Am I on the wrong track about the functionality / usage here? Isn't the outcome supposed to be the same?

Sorry for the wall of text, I've never opened an issue ticket for a framework before.

Comment #1

Posted on Mar 11, 2013 by Massive Elephant

Ah, turns out I had the wrong reference to my Window (and this my TextArea). In order to fix this issue, I called this:

getOwner().runInEventThread(new Action() { @Override public void doAction() { TextArea act = (TextArea) getOwner().getActiveWindow().getComponentAt(2); //obviously this index varies, but I just counted it from which order I called addComponent() textArea.insertLine(0, message); getOwner().invalidate(); } });

This gave me a correct reference to my TextArea. Anyway, the issue is resolved now, please close this and file it under "noobie mistake"! Thanks for the great framework :-)

Comment #2

Posted on Mar 20, 2013 by Grumpy Ox

Okay... So you called invalidate() on the wrong Window? Or appendText("...") on the wrong object?

Comment #3

Posted on Mar 20, 2013 by Massive Elephant

Yeah exactly. My doAction in my button had a reference different from the one I got when I called my own method. Obviously since doAction was able to update the window and my method wasn't, I figured I somehow had to get the reference to the window by other means that directly addressing it (I was using "this." to refence to my window).

Long story short: I checked up on the ID's using the NetBeans debugger and checked for consistency errors. And yes, as you said, I was calling invalidate() on a wrong window - which to me (at first) didn't make sense, because I was using "this.invalidate()". But it's just one of those things that eludes new players like myself - reference consistency.

Sorrry about the wall of text. I'm struggling to understand the issue at hand here and because of that, I'm not really sure how much information is relevant to the case.

Thank you!

Comment #4

Posted on Apr 20, 2013 by Grumpy Ox

All right, good to hear it worked out in the end.

Status: Verified

Labels:
Type-Defect Priority-Medium