Results 1 to 3 of 3
Thread: Implementing swingworker
- 02-23-2012, 12:17 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
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 stackoverflow.com
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; @Override protected Void doInBackground() throws Exception { text = textEditor1.getText().toString(); return null; } @Override protected void done() { try { get(); textEditor2.setText(text); } catch (Exception ex) { System.out.println(ex); } } }; worker.execute(); }
- 02-23-2012, 01:54 AM #2
Re: Implementing swingworker
Every update to that huge String copies the whole thing and adds on the new String to create a new Huge String.inserted 5000 lines and tried to type, i think as the line goes on increasing, the updation in textEditor2 is becoming very slow.
Can you do it another way?
-
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
-
When do I use SwingWorker?
By TacoManStan in forum AWT / SwingReplies: 8Last Post: 10-24-2011, 12:40 AM -
SwingWorker
By 3.14.TR in forum Threads and SynchronizationReplies: 3Last Post: 03-14-2011, 04:53 PM -
How to stop SwingWorker?
By JStarter in forum AWT / SwingReplies: 14Last Post: 07-20-2010, 04:36 PM -
Using SwingWorker
By viking90 in forum New To JavaReplies: 1Last Post: 04-24-2010, 09:17 AM -
swingworker
By musiigedeo in forum AWT / SwingReplies: 1Last Post: 07-26-2007, 12:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks