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

    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:
    [SIZE="2"]
                this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
                // Préparation de la minuterie...
                Timer ModifierLaBarreDeProgression=new Timer(1000, new ActionListener()
                {
    
                    @Override
                    public void actionPerformed(ActionEvent e)
                    {
                        try
                        {
                            if(!bWorkDone)
                                ((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.setLogTimers(true);
                ModifierLaBarreDeProgression.setInitialDelay(500);
                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];
                    
                    int Verif=Source.read(Buffer);
                    if(Verif==LongueurFichier)
                    {
                        Destination.write(Buffer);
                        Destination.flush();
                    }
                    Destination.close();
                    Source.close();
    
                    //((JProgressBar)jPanelStatusBar.getComponent(2)).setValue(cptEtatAvancement);
                    //((JProgressBar)jPanelStatusBar.getComponent(2)).setStringPainted(true);
                    GlobalStatus=cptEtatAvancement;
                    
                }
                ModifierLaBarreDeProgression.stop();                                    // on arrête la minuterie...
                bWorkDone=true;
                this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            [/SIZE]
    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
    Posts
    9
    Rep Power
    0

    Default

    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
    Posts
    14
    Rep Power
    0

    Default

    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, 05: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, 01:26 PM
  3. Java - Linux Issue
    By mhyndavi in forum Advanced Java
    Replies: 4
    Last Post: 06-15-2010, 07:40 AM
  4. [SOLVED] Netbeans Desktop App &amp; JProgressBar
    By SebScoFr in forum NetBeans
    Replies: 3
    Last Post: 11-28-2008, 12:00 AM
  5. To run Netbeans on Linux Fedora 8
    By rorootot in forum NetBeans
    Replies: 11
    Last Post: 07-22-2008, 05: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
  •