Results 1 to 3 of 3
  1. #1
    soundlord is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default [Linux 11.1 and NetBeans 6.9.1] JProgressBar issue

    Greetings !!

    I'm trying to update the ProgressBar set on a custom StatusBar composed in one JPanel object and components added in using the editor (so the different code is added in the initComponent of the main class).

    I realized and then after read about the fact that swing objects can not be updated until the event thread is used. In other words I can't do simply SetValue() from the code in a method.

    I read that often the programmers are using invokeLater method but this solution wasn't planned and it won't work in my situation.

    The solution that was nice for me was to use a Timer.
    I tested it it worked (but neverending) and now it won't work at all !!!

    Here is the code:

    Java Code:
                this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
                // Préparation de la minuterie...
                Timer ModifierLaBarreDeProgression=new Timer(1000, new ActionListener()
                    public void actionPerformed(ActionEvent e)
                                ((JProgressBar) jPanelStatusBar.getComponent(2)).setValue(GlobalStatus);
                                // Très mauvais au niveau de la programmation car on va chercher une variable globale et on l'utilise dans une méthode locale mais
                                // nous n'avons pas le temps de trouver un mécanisme plus "orienté objet" nous sommes dans l'urgence ^^ (prétextes, prétextes, ...)
                        catch (Exception ex)
                            throw new UnsupportedOperationException("Not supported yet.");
                // C'est actionPerformed qui va être appelé après les milli-secondes écoulées...
                ModifierLaBarreDeProgression.start();                               // on lance la minuterie
                for(int cptEtatAvancement=0;cptEtatAvancement<FilesToCopy.size();cptEtatAvancement++)
                    FileInputStream Source=new FileInputStream(FilesToCopy.get(cptEtatAvancement));
                    FileOutputStream Destination=new FileOutputStream(LibraryPath+"/"+FilesToCopy.get(cptEtatAvancement).getName());
                    long LongueurFichier=FilesToCopy.get(cptEtatAvancement).length();
                    byte[] Buffer=new byte[(int)LongueurFichier];
                ModifierLaBarreDeProgression.stop();                                    // on arrête la minuterie...
                this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    It worked but I don't know how and why (the progress bar was indicating values but I forgotten to stop the Timer so the behaviour was strange)...
    Now if I put a breakpoint on the line in actionPerformed() there is nothing happening. And curiously the debug line
    Java Code:
    Timer ringing: javax.swing.Timer@782cbc86
    came after the entire job was done !!
    Be awared that the process takes more than one second so this is not an issue related to the process to be executed before the first call to actionPerformed by the Timer.
    Now I wonder if it is, in this case, better to use the "swing" timers ?
    I read that they exist but I never used them (it seems more complicated to use).
    Do I need to put that 'future TimerTask' here in example in a background process ? That's very strange to have to do so, I was believing JProgressBar was having its proper thread to update its own status, but I was wrong.

  2. #2
    stringargs is offline Member
    Join Date
    Nov 2010
    Rep Power


    wtf is linux 11.1?
    I thought the linux kernel version was somewhere around 2.6..

  3. #3
    soundlord is offline Member
    Join Date
    Mar 2011
    Rep Power


    I omitted SuSE 11.1 kernel 2.6, I'm sorry ^^

    I did tried all the different stuffs explained in:

    Using Timers in Swing Applications

    and different sources from books, but I'm still doubtful about how my application is reacting.

    I'll dig and try more solutions...

Similar Threads

  1. Replies: 1
    Last Post: 12-18-2010, 04:44 PM
  2. problem with permission and netbeans 6.9 on linux
    By mr_anderson in forum NetBeans
    Replies: 8
    Last Post: 08-27-2010, 12:26 PM
  3. Java - Linux Issue
    By mhyndavi in forum Advanced Java
    Replies: 4
    Last Post: 06-15-2010, 06:40 AM
  4. [SOLVED] Netbeans Desktop App &amp; JProgressBar
    By SebScoFr in forum NetBeans
    Replies: 3
    Last Post: 11-27-2008, 11:00 PM
  5. To run Netbeans on Linux Fedora 8
    By rorootot in forum NetBeans
    Replies: 11
    Last Post: 07-22-2008, 04:23 AM

Posting Permissions

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