Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 26th, 2013, 02:54 AM
Wetmelon's Avatar
Wetmelon Wetmelon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Location: London, ON
Posts: 322 Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 9 h 32 m 53 sec
Reputation Power: 213
Swing - JLabel update is locked out by continuation of program

Hello!

I have a JLabel in a JDialog to show users what's going on, but sometimes it updates out of order or too late to be of use.

Code:
JLabel lZipStatus;
lZipStatus.setText("Installing, please wait...");
unzipFile(zFile);
lZipStatus.setText("Installation Complete.");


Often the wait message appears after the zip file has already begun executing, or it appears AFTER the "Installation Complete" message, effectively overwriting it. What can I do to avoid this behaviour?
__________________
<Tetrad> the program I just wrote 1) compiled the first time without any errors and 2) worked like it was supposed to
<Tetrad> I don't know whether to be proud or scared to death
Quote:
Originally Posted by DaWei_M
That covers a multitude of your sins, right there.

Reply With Quote
  #2  
Old January 26th, 2013, 06:16 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,952 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 33 m 55 sec
Reputation Power: 345
Are you talking about calls to setText() only showing what was passed in the last call to setText()? The JVM doesn't get to update the GUI after each call to setText(). When it gets control the earlier calls to setText() are gone and ony the last is used.

Is the code being executed on the EDT? That locks the JVM out from being able to update the GUI.

Reply With Quote
  #3  
Old January 26th, 2013, 02:55 PM
Wetmelon's Avatar
Wetmelon Wetmelon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Location: London, ON
Posts: 322 Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 9 h 32 m 53 sec
Reputation Power: 213
Quote:
Is the code being executed on the EDT? That locks the JVM out from being able to update the GUI.


It's being executed under "bAddModButtonActionPerformed" method, so I guess so?

Reply With Quote
  #4  
Old January 26th, 2013, 04:32 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,952 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 33 m 55 sec
Reputation Power: 345
If you start a new thread to do the long task and exit the action listener, the EDT will be able to update the GUI to show the waiting message. When the long task ends, it can update the GUI with the completed message.

Reply With Quote
  #5  
Old January 26th, 2013, 09:59 PM
Wetmelon's Avatar
Wetmelon Wetmelon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Location: London, ON
Posts: 322 Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level)Wetmelon User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 9 h 32 m 53 sec
Reputation Power: 213
So THAT'S what this code is doing:

Code:
java.awt.EventQueue.invokeLater(new Runnable() {
	    mainFrame frame = new mainFrame();
	    
	    @Override
	    public void run() {
		frame.setLocationByPlatform(true);
		frame.setVisible(true);
	    }


I'm using pre-gen'd code from NetBeans, but I didn't understand why I needed this in my main. It all makes sense now!

So basically just create a new Runnable object in my ActionPerformed, override run() with the call to "unzipFile()" and run it immediately?


EDIT: Also needed to create an actual Thread!

Code:
lZipStatus.setText("Installing, please wait...");
	Thread thread = new Thread(new Runnable() {

	    @Override
	    public void run() {
		unzipFile(tfZipPath.getText());
	    }
	});
	thread.start();


I had a large large portion of unzipFile() method being executed within the ActionPerformed. It was iterating through the ZipFile and for each entry it was sending that entry to another method called "writeZipToFile". The way you've explained it, I've offloaded anything that would lock the GUI to another thread, effectively allowing the user to interact with the GUI while loops and other things are running. Not something I had ever thought about, but I'll be sure to implement in this way going forward.

Thanks a ton!

Last edited by Wetmelon : January 27th, 2013 at 01:19 AM.

Reply With Quote
  #6  
Old January 27th, 2013, 06:01 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,952 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 33 m 55 sec
Reputation Power: 345
You might want to disable some of the buttons while the long running task is executing to keep the user from starting another one at the same time.
Then enable the button when its ok to do it again.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Swing - JLabel update is locked out by continuation of program

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap