Results 1 to 3 of 3
- 04-16-2011, 02:40 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
[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:
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)...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]
Now if I put a breakpoint on the line in actionPerformed() there is nothing happening. And curiously the debug linecame after the entire job was done !!Java Code:Timer ringing: javax.swing.Timer@782cbc86
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.
- 04-17-2011, 06:46 PM #2
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
wtf is linux 11.1?
I thought the linux kernel version was somewhere around 2.6..
- 04-17-2011, 10:54 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
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
-
how can i install latest version of NetBeans on debian linux?
By ali zi zeperto in forum NetBeansReplies: 1Last Post: 12-18-2010, 04:44 PM -
problem with permission and netbeans 6.9 on linux
By mr_anderson in forum NetBeansReplies: 8Last Post: 08-27-2010, 12:26 PM -
Java - Linux Issue
By mhyndavi in forum Advanced JavaReplies: 4Last Post: 06-15-2010, 06:40 AM -
[SOLVED] Netbeans Desktop App & JProgressBar
By SebScoFr in forum NetBeansReplies: 3Last Post: 11-27-2008, 11:00 PM -
To run Netbeans on Linux Fedora 8
By rorootot in forum NetBeansReplies: 11Last Post: 07-22-2008, 04:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks