Results 1 to 2 of 2
- 11-15-2012, 01:31 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
[Solved] Threading this so it doesn't freeze
Hey, I am new to java and need some help
i have a Swing GUI but the way i got it setup is it freezes the whole gui untill its finished doing something...
code:
It never has enaugh time to set the label to "Processing (dont close me)" it freezes then after its done it changes to "Finished" :(Java Code:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO Single download button clicked jLabel6.setText("Processing (dont close me)"); section = jComboBox1.getSelectedItem().toString(); page = jSpinner1.getValue().toString(); process.url(url, section, page); jLabel6.setText("Finished"); }
how can i fix it(is there another way to freeze the gui(i don't want people to go into other menus while its processing)
maby setEnabled false?
ps. its a mass image downloader
Thanks
-----------------EDIT-----------
Solved :)
Java Code:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO Single download button clicked jLabel6.setText("Working . . ."); jButton1.setEnabled(false); jButton2.setEnabled(false); jButton3.setEnabled(false); Thread worker = new Thread() { public void run() { section = jComboBox1.getSelectedItem().toString(); page = jSpinner1.getValue().toString(); process.url(url, section, page); SwingUtilities.invokeLater(new Runnable() { public void run() { jLabel6.setText("Ready"); jButton1.setEnabled(true); jButton2.setEnabled(true); jButton3.setEnabled(true); } }); } }; worker.start(); // So we don't hold up the dispatch thread. }Last edited by radexito; 11-15-2012 at 01:51 AM. Reason: solved
- 11-15-2012, 08:14 AM #2
Re: [Solved] Threading this so it doesn't freeze
You need to go through this Tutorial Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Threading GUI still doesn't work
By devdon in forum Threads and SynchronizationReplies: 7Last Post: 04-06-2012, 10:56 PM -
App freeze during MySQL connestion
By meiilax in forum JDBCReplies: 3Last Post: 01-06-2012, 09:34 AM -
Freeze issue
By TomatoTom in forum Threads and SynchronizationReplies: 3Last Post: 05-09-2011, 12:13 PM -
Freeze cursor
By Gog in forum New To JavaReplies: 7Last Post: 01-14-2011, 10:29 PM -
Serial Comm freeze
By java_dude in forum NetworkingReplies: 3Last Post: 01-13-2011, 10:09 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks