Problems with JProgressBar!!!

C

C.Steamer

Basically I have this program that runs the following code. I get the error
that you see at the bottom there. The thing is I don't get it all the time
only once and a while. I have heard that switching between indeterminent
mode and determinate mode can cause some resizing problems. I have heard of
a solution to set the String to null while in determinate and set it to the
empty string when in indeterminate mode. I tried that and it doesn't seem to
work. I might have done it wrong. I suspect that I am only running into
problems once and a while because the indeterminate bar is in the middle of
the progress bar when It exits indeterminate mode causing some problem
with the string of non indeterminate mode. I don't know forsure. Also if I
comment out the indeterminate stuff, it works fine. but I would like to be
able to use this feature. Any suggestions? Thanks



This is where I create the progress Bar



JProgressBar progressBar = new JProgressBar();

progressBar.setStringPainted(true);





This is where I use the progress bar



panel.getProgressBar().setIndeterminate(true);

int totalFiles = countNonHiddenFiles(file);

panel.getProgressBar().setIndeterminate(false);


panel.getProgressBar().setMinimum(0);

panel.getProgressBar().setValue(0);

panel.getProgressBar().setMaximum(totalFiles);


recurseDirectories(file);





This is the error I get when running the program.



java.lang.NullPointerException

at javax.swing.plaf.basic.BasicProgressBarUI.updateSizes(Unknown Source)

at javax.swing.plaf.basic.BasicProgressBarUI.getBox(Unknown Source)

at
com.sun.java.swing.plaf.windows.WindowsProgressBarUI.paintIndeterminate(Unknown
Source)

at javax.swing.plaf.basic.BasicProgressBarUI.paint(Unknown Source)

at javax.swing.plaf.ComponentUI.update(Unknown Source)

at javax.swing.JComponent.paintComponent(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintChildren(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)

at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)

at javax.swing.JComponent._paintImmediately(Unknown Source)

at javax.swing.JComponent.paintImmediately(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown
Source)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)
 
B

Babu Kalakrishnan

C.Steamer said:
This is where I use the progress bar



panel.getProgressBar().setIndeterminate(true);

int totalFiles = countNonHiddenFiles(file);

panel.getProgressBar().setIndeterminate(false);


panel.getProgressBar().setMinimum(0);

panel.getProgressBar().setValue(0);

panel.getProgressBar().setMaximum(totalFiles);

Are the above calls (the ones on the progressbar) made in the Event
Dispatch Thread ? If not, try moving them to the EDT using a
SwingUtilities.invokeLater wrapper.

BK
 
C

***C.Steamer***

Yeah that fixed it, I totally forgot about switching to the event thread
first. Funny thing was In other parts of the same class I had code that did
that very thing, just slipped my mind. Thanks Alot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top