Results 1 to 2 of 2
  1. #1
    viking90 is offline Member
    Join Date
    Apr 2010
    Rep Power

    Default Using SwingWorker

    I have a JButton that exchanges the contents of two JTextAreas:
    Java Code:
    String temp = leftTextArea.getText();
    Let's assume that this operation can be quite time-consuming (i.e. moving large chunks of text). Therefore, I should put this into a separate thread, so that user can use the GUI while the text in both of the JTextAreas is being processed.
    I have read about SwingWorker class, but since I've never used that before, I am not quite sure how to do this using the SwingWorker.

    This is what I've come up with so far:
    Java Code:
    new SwingWorker<Void, Void>() {
    		String text1, text2;
    		public Void doInBackground() {
    	        	  text1 = leftTextArea.getText();
    	        	  text2 = rightTextArea.getText();
    	        	  return null;  
    	        public void done() {
    Is the above code OK? Or should I move the two lines in the done() method to the doInBackground() and leave the body of done() empty?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Don't exchange those Strings but exchange the Documents between those two JTextAreas.

    kind regards,


Similar Threads

  1. Swingworker or new thread
    By cotarelo in forum Threads and Synchronization
    Replies: 3
    Last Post: 03-24-2010, 06:59 PM
  2. SwingWorker question
    By cotarelo in forum Threads and Synchronization
    Replies: 16
    Last Post: 03-23-2010, 11:29 AM
  3. SwingWorker Problem
    By Berkan in forum Threads and Synchronization
    Replies: 10
    Last Post: 03-11-2010, 03:28 AM
  4. SwingWorker Opinions
    By frejon26 in forum AWT / Swing
    Replies: 3
    Last Post: 04-13-2009, 08:41 PM
  5. swingworker
    By musiigedeo in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2007, 12:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts