I tried out the function of the JProgressBar in Java. But there is a problem I couldn't solve:
When I set the minimum to zero, the maximum value to 100 and the current value to 6 then nothing will be displayed. The progress bar is empty. If I put 7 as current value then it works. It seems to be a problem with any empty border or other space. The problem occurs with Windows 7 and only if the UIManager is set to SystemLookAndFeel.
Does anyone knows this problem and has a solution for this? Below is my code:
package lab;
import java.awt.FlowLayout;
import javax.swing.JDialog;
import javax.swing.JProgressBar;
import javax.swing.UIManager;
import core.Config;
public class ProgressSample extends JDialog {
public ProgressSample() {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
// Nothing is displayed
JProgressBar progressSix = new JProgressBar(0, 100);
progressSix.setValue(6);
getContentPane().add(progressSix);
// This works
JProgressBar progressSeven = new JProgressBar(0, 100);
progressSeven.setValue(7);
getContentPane().add(progressSeven);
pack();
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
ProgressSample dialogTest = new ProgressSample();
dialogTest.setVisible(true);
}
}
The java code for a Windows native look-and-feel progress bar renders using PROGRESSCHUNKSIZE
steps in the manner of the original windows progress bar. Please see the source for the Windows JProgressBar.
It's just not rendering it smoothly. If you step the progress bar you can see the chunks.
It may be customizable, but I don't know how you would accomplish it.
Origin of the Issue
The original windows XP progress bar was in little boxes. The theme defined a size of the box, and the gap between the box. For Vista and later, the theme was changed to specify the gap between the box as 0, but never reset the size of the box to 1 pixel. Reading the value through the OpenThemeData
and GetThemeInt
Win32API
functions reveals that the chunk size is 6
for my theme (Windows 8).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With