• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextArea listening for messages

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,

I'm fairly new to swing at least on any sort of significant level, so if I don't explain something too well to start, I apologize in advance. I have a non-GUI based application that I developed, and taking the code that somebody wrote already using netbeans for an External GUI Launcher type program and I'm integrating it directly into my existing code. The plan is to eventually create a new GUI, but in order to have a better interaction between the user and the product without waiting for months of GUI development i figured I would start here.

So the GUI part of the program now is based off a SingleFrameApplication, and currently this SingleFrameApplication will fire off a JDialog box at a certain point. From this JDialog box, we used to kick off my program using

p = Runtime.getRuntime().exec("my_program.cmd");

we would then listen for output in a jtextarea by




This worked out ok for what it was. But now I want to be able to (from outside the gui code) directly send my logging to this text area (and eventually update other text areas and other swing objects).

At first I thought all i would have to do would be to access the component, but that is not working out so well. Then I thought I'd try to add a Listener to the textArea, but you can't do that.

So my code is all over the place, and before i follow up with actual code if needed, I was hoping somebody had run into something along these lines and can point me in a direction that makes sense to start.

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Richard wrote:At first I thought all i would have to do would be to access the component, but that is not working out so well.



That's what I would have thought too. So would you like to clarify "not working out so well"?

In the meantime I'm going to guess that you're running this log-producing code in the Swing thread. If that phrase doesn't ring a bell, check out the tutorial: Lesson: Concurrency in Swing.
 
Jason Richard
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Jason Richard wrote:At first I thought all i would have to do would be to access the component, but that is not working out so well.



That's what I would have thought too. So would you like to clarify "not working out so well"?

In the meantime I'm going to guess that you're running this log-producing code in the Swing thread. If that phrase doesn't ring a bell, check out the tutorial: Lesson: Concurrency in Swing.



So the log producing code is in the Swing thread but in a class outside of the GUI itself. If a button is pressed I'm now I'm just launching my old codes main

MyCode.main(args);

and the code kicks off great, and as of right now All my log files are created, and my console output is generated correctly. All i was trying to do was for starters was to duplicate the console output to the text area.

I will take a look at that link you provided thanks.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Richard wrote:So the log producing code is in the Swing thread but in a class outside of the GUI itself.



Here's a basic rule of Java: it doesn't make any difference what class a piece of code is located in. As long as the code can get a reference to an object, it can call that object's methods (if they are accessible to the code, that is).
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Then I thought I'd try to add a Listener to the textArea, but you can't do that.

try a DocumentListener
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic