Results 1 to 3 of 3
  1. #1
    shivam0101 is offline Member
    Join Date
    Mar 2010
    Rep Power

    Default Implementing swingworker

    Thought of making a small textEditor. It will contain two textareas, one for entering the text and one for error display. As for my understanding, SwingWorker works in background so there will be no delay in the UI updation. For checking, i wrote the below code and inserted 5000 lines and tried to type, i think as the line goes on increasing, the updation in textEditor2 is becoming very slow. Is the implementation of the swingworker is correct in the code?

    textEditor1 and textEditor2 are JTextarea

    This i have allready posted in

    If some how i could manage avoid of making a new worker everytime i press a key i think it should work.

    Thanks in advance
    Java Code:
    private void editorKeyPressed(java.awt.event.KeyEvent evt) {
    SwingWorker worker = new SwingWorker<Void, Void>() {
        String text = null;
        protected Void doInBackground() throws Exception {
            text = textEditor1.getText().toString();
            return null;
        protected void done() {
            try {
            } catch (Exception ex) {

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Implementing swingworker

    inserted 5000 lines and tried to type, i think as the line goes on increasing, the updation in textEditor2 is becoming very slow.
    Every update to that huge String copies the whole thing and adds on the new String to create a new Huge String.
    Can you do it another way?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Implementing swingworker

    Cross posted on stack overflow without notifying us. Please understand that it is fine to cross post question, but it is not polite to not notify us that you're doing so as it implies that you don't understand that we're all volunteers and you don't value our time. Please let us know when you do this so that we don't duplicate work that's already been done.

Similar Threads

  1. When do I use SwingWorker?
    By TacoManStan in forum AWT / Swing
    Replies: 8
    Last Post: 10-24-2011, 12:40 AM
  2. SwingWorker
    By 3.14.TR in forum Threads and Synchronization
    Replies: 3
    Last Post: 03-14-2011, 05:53 PM
  3. How to stop SwingWorker?
    By JStarter in forum AWT / Swing
    Replies: 14
    Last Post: 07-20-2010, 04:36 PM
  4. Using SwingWorker
    By viking90 in forum New To Java
    Replies: 1
    Last Post: 04-24-2010, 09:17 AM
  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