• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Newbie help needed Java Gui can't setText

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swing is not threadsafe. When you want to manipulate Swing widgets all manipulation has to be done from inside the EventDispatchThread.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gaz xxx wrote:
It works perfectly !!!

Thank you for your help and patience.



You are quite welcome, and again glad to see you here!
 
Marshal
Posts: 80764
488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Gary Hill
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic