Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: [Asking] Listener on Text Area

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    30
    My Mood
    Cool
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default [Asking] Listener on Text Area

    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


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: [Asking] Listener on Text Area

    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?

  3. #3
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: [Asking] Listener on Text Area

    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.

  4. #4
    Member
    Join Date
    Sep 2012
    Posts
    30
    My Mood
    Cool
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: [Asking] Listener on Text Area

    Hi All,

    Sorry if my english isn't good

    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

  5. #5
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: [Asking] Listener on Text Area

    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.

  6. #6
    Member
    Join Date
    Sep 2012
    Posts
    30
    My Mood
    Cool
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: [Asking] Listener on Text Area

    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

  7. #7
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: [Asking] Listener on Text Area

    Quote Originally Posted by ardisamudra View Post
    I don't know what do you mean "PropertyChangeSupport in the client", Do you mean PropertyChangeSupport in the server?
    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.

    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.
    It's hard to know what is not working with just the information provided, but a few suggestions:
    • 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.

  8. #8
    Member
    Join Date
    Sep 2012
    Posts
    30
    My Mood
    Cool
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: [Asking] Listener on Text Area

    Ok thanks,

    Now I can write the log

Similar Threads

  1. problem with printing to text area
    By gatorsgirl in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 25th, 2012, 10:06 AM
  2. Updating a text area from a JtextField! HELP
    By Java Programmer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 22nd, 2012, 08:05 PM
  3. Text file to text area and Radiobuttons?
    By donaldmax in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 27th, 2011, 04:45 AM
  4. Display in a text area
    By susieferrari in forum Java Theory & Questions
    Replies: 21
    Last Post: March 22nd, 2011, 09:56 AM
  5. Problem in implementing mortgage calculator
    By American Raptor in forum AWT / Java Swing
    Replies: 1
    Last Post: April 1st, 2009, 02:09 PM