Appending text to a JTextArea on button press?

You are likely shadowing a variable -- declaring it more than once, but initializing a local variable not the class field, and so the class field remains null.

You are likely shadowing a variable -- declaring it more than once, but initializing a local variable not the class field, and so the class field remains null. Edit: Yep, sure enough you do. In your constructor you have JTextArea outputLog = new JTextArea(" "); This re-declares the outputLog variable, and so you are initializing only the variable local to the constructor.

The solution is not to redeclare the variable but instead initialize the class field. So change the above to outputLog = new JTextArea(" "); You will need to do this for every variable that needs to be accessed in the class scope. For those that are OK to declare locally, do so, but in the sake of safety, get rid of their corresponding class declaration so as not to risk causing the same error in the future.

How could I have been so blind! Thanks HFoE! – Michael llman Oct 16 at 17:34 @Michael: You're welcome!

– Hovercraft Full Of Eels Oct 16 at 17:36.

Your error is that the instance variable outputLog is not initialized.

Your code not done on EDT, you have to wrap tht into invokeLater() EventQueue. InvokeLater(new Runnable() { @Override public void run() { outputLog. SetText(outputLog.getText() + System.

GetProperty("line. Separator") + text); } }).

The OP doesn't need to use EDT with JTextArea.append() which is thread-safe. And anyway, actionPerformed() is always called from the EDT! – jfpoilpret Oct 17 at 7:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions