Results 1 to 2 of 2
  1. #1
    radexito is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default [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:
    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");
        }
    It never has enaugh time to set the label to "Processing (dont close me)" it freezes then after its done it changes to "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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    10,096
    Rep Power
    17

    Default Re: [Solved] Threading this so it doesn't freeze

    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. Threading GUI still doesn't work
    By devdon in forum Threads and Synchronization
    Replies: 7
    Last Post: 04-06-2012, 10:56 PM
  2. App freeze during MySQL connestion
    By meiilax in forum JDBC
    Replies: 3
    Last Post: 01-06-2012, 09:34 AM
  3. Freeze issue
    By TomatoTom in forum Threads and Synchronization
    Replies: 3
    Last Post: 05-09-2011, 12:13 PM
  4. Freeze cursor
    By Gog in forum New To Java
    Replies: 7
    Last Post: 01-14-2011, 10:29 PM
  5. Serial Comm freeze
    By java_dude in forum Networking
    Replies: 3
    Last Post: 01-13-2011, 10:09 PM

Posting Permissions

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