This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing To A JTextArea

 
Alan Jackson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys.

I have a java program thats works with an LDAP server. Basically, it gets some values, and outputs them to the dos console window. Problem is, I want them to go to the JTextArea on the GUI.

I have one method that creates the GUI, one that acts as actionPerformed (when I push the connect button) and then methods for getting the info I need. What I need to do is in the methods that get the info, I need to write to the text area. But because it is private I cant do it.

Anyone know how I can write to a private JTextArea from another method?

Cheers!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could pass that text area to the method.





That is one way. There are some better ways albeit a bit more involved as it has to do with observable patterns and what not. You could also just make the text area public. Or you could have a public call back method that writes to the private text area.
 
Alan Jackson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much. What would the someClass bit you mentioned refer to?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alan Jackson:
Thanks very much. What would the someClass bit you mentioned refer to?


Well, since you said that you can't access the JTextArea object because it is private, I assumed your method for accessing LDAP was in a different class than your JTextArea. someClass is that other class. If this is not the case, I'd be cuirous as to why you think you can't access a private member from the same class.
 
Alan Jackson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it working, thanks Gregg
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic