aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Newbie help needed Java Gui can't setText Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Newbie help needed Java Gui can Watch "Newbie help needed Java Gui can New topic
Author

Newbie help needed Java Gui can't setText

Gary Hill
Greenhorn

Joined: Nov 06, 2010
Posts: 15
Hi,

I have looked verywhere on the net but cannot find an anser to my simple problem.

I wish to send text to a jTextArea the jTextArea is in a class called public class NewJFrame.

From another class Main i want to send text.






If i uncomment //name= ("gb"); i can then see the correct text in the jTextArea.

If i send it from Main as shown above it doesn't show the text?

The println shows me that the method has received the string.


I have been trying for hours to work out why its not working but i cannot find out what is wrong!

Can you please help i know its easy but as i'm still learning it isn't easy fro me.

Regards


Gary
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Swing is not threadsafe. When you want to manipulate Swing widgets all manipulation has to be done from inside the EventDispatchThread.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
This has nothing to do with thread issues, but I'm not sure I can tell what the problem is based on the snippets of code that you've provided. I wonder if you have a reference problem -- that you're making method calls or changes to the wrong GUI reference, perhaps one that's not displayed, but again, without more code, I'm just guessing. One big problem I see is that you're naming your variable the exact same as your class "NewJFrame" complete with the exact same capitalization. This likely isn't causing your problem but is very bad practice and you'll want to correct this as soon as possible.

I recommend that you create a small compilable runnable program that has just enough code to run, display a small simple GUI and display your problem, but no unnecessary code unrelated to your problem, an SSCCE

Much luck with solving your problem and welcome to the Ranch!!

Pete
Gary Hill
Greenhorn

Joined: Nov 06, 2010
Posts: 15
Hi Pete

You were right, in simplifying the code to display on here i realised that a few days ago, I had set up a method to set the windows look and feel in Java. And in my Class Main i declared

NewJFrame LookandFeel = new NewJFrame(); // Sets up the Object.
LookandFeel.setVisible(true); // turns on JFrame.

Then few days later started to right more code and forgot about the above, as soon as I changed the code to:

LookandFeel.textData("gb");

It works perfectly !!!

Thank you for your help and patience.


Regards

Gary
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
gaz xxx wrote:
It works perfectly !!!

Thank you for your help and patience.


You are quite welcome, and again glad to see you here!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
And welcome to the Ranch
Gary Hill
Greenhorn

Joined: Nov 06, 2010
Posts: 15
Thank you,

Pete and Campbell for making me feel welcome!

I know I will have a lot of questions which i iwll try and find answers for before asking on here.

I do find Java a hard thing to learn, i have dabbled in VB.Net but i do beleive that Java is the way to go!

Regards

Gary
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Newbie help needed Java Gui can't setText