Hi, All
I have a problem with textarea in my swing application.
I want my textarea show string or something like log when the application is runing.
Anyone know what is the proper listener to do that ??
Thanks
Printable View
Hi, All
I have a problem with textarea in my swing application.
I want my textarea show string or something like log when the application is runing.
Anyone know what is the proper listener to do that ??
Thanks
That would depend on what you want to listen for?
Mouse move? Mouse enter? Mouse exit? Mouse click? Mouse drag? Key down? Key up? Key typed? Iteration in a loop? ... so many things to hear.. what is it you are trying to do?
If your log display gets very large, I'd recommend using a JList and not a JTextArea. Otherwise I agree with jps -- please tell us just exactly what are you trying to do here? Listen to what? Please tell us all of the gory details.
Hi All,
Sorry if my english isn't good :cool:
Actually I create my own server, and I want to show my log in textArea. So listener doesn't come from mouse or key, but it's triggered by client.
Anyone know about that ?
Thanks :)
Consider using PropertyChangeSupport in the client, making the incoming String a "bound property" (check the tutorial on how to do this), and then having your GUI add a PropertyChangeListener to listen for new incoming Strings which it can then display. Again, if the log will get large, display it in a JList which can handle much larger amounts of data (and still be responsive) compared to a JTextArea.
Hi carmudgeon,
I don't know what do you mean "PropertyChangeSupport in the client", Do you mean PropertyChangeSupport in the server? In my case there is incoming packet and I write to file log, but I get trouble when to show the log on text area. I already add PropertyChangeSupport, but there is no log in textarea.
Do you have another idea??
Please help me
No, I gather that you're trying to display this information in a GUI that's run on the client machine, correct? So the property change support must be in the object that is receiving the new data.
It's hard to know what is not working with just the information provided, but a few suggestions:Quote:
In my case there is incoming packet and I write to file log, but I get trouble when to show the log on text area. I already add PropertyChangeSupport, but there is no log in textarea.
- I would be sure that the PropertyChangeSupport is a SwingPropertyChangeSupport instance and is constructed with SwingPropertyChangeSupport(sourceBean, true) as this will help make sure that its firePropertyChange(...) method is called only on the Swing event thread or EDT.
- Make sure (and this is critical) that you're not listening for packets on the EDT that instead it's done on a background thread.
- Only change the bound property via its mutator method, that you never modify it directly.
- Your Swing code will need to add a PropertyChangeListener to the packet-monitoring class and then respond to changes in the property of interest.
If this doesn't help, then you may need to tell and show us more.
Ok thanks,
Now I can write the log :)