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 4 of 4

Thread: JtextArea update issue.

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Angry JtextArea update issue.

    Hi,

    I'm currently writing a application, which on a mouse click runs several methods which updates a JtextArea. The problem is even though I'm updating the text area with each method call, it doesn't actually update until everything in the mouseclick has run..

    This can take quite a while to run through everything and I would like to see the text area update with each call instead of waiting until everything is done

    		btnBeginTest.addMouseListener(new MouseAdapter() {
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				DataCollector dc = new DataCollector();
     
    				dataCollected.append("Begining Test...\n\n");
    				dataCollected.append("Collecting System Information... \n\n");
    				dataCollected.append(dc.getSystem());
                                    ... lots more like this...

    any ideas how I can make the text area update the way I intended?

    Thanks.


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: JtextArea update issue.

    Swing uses one particular thread to call things like your mouseClicked() - the so called event dispatch thread (EDT). Painting is also done on this thread which explains why mouseClicked() must complete before anything "shows up". What you are seeing is the reason why code you write that will be invoked on the EDT (handlers and painting code, eg) *must* complete quickly.

    If something is going to take a while (>100ms?) then it should happen on another thread. Your mouseClicked() should use another thread to do it's work, updating the gui when it's done.

    Google or browse through Oracle's Tutorial where the EDT and using multiple threads is discussed and illustrated.

  3. The Following User Says Thank You to pbrockway2 For This Useful Post:

    Rihx (April 30th, 2012)

  4. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JtextArea update issue.

    Thanks, that's what I thought. I was hoping to avoid having to write another method thread, but I guess there is no way around it.

  5. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JtextArea update issue.

    never mind.
    Last edited by Rihx; May 2nd, 2012 at 11:48 AM. Reason: figured it out...

Similar Threads

  1. [SOLVED] JTextArea font/character count issue
    By psychobeagle12 in forum AWT / Java Swing
    Replies: 7
    Last Post: April 25th, 2012, 06:17 PM
  2. JTextArea customization
    By Bagzli in forum AWT / Java Swing
    Replies: 2
    Last Post: April 23rd, 2012, 08:08 AM
  3. Java Issue / Cache issue
    By VisualPK in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2012, 08:43 PM
  4. Issue with Java 6 Update 18 and WebApp
    By jpa in forum Java Theory & Questions
    Replies: 1
    Last Post: October 12th, 2011, 07:23 AM
  5. JTextArea Problem
    By grimx in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 10th, 2011, 07:13 PM