Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

java - JProgressBar: low values will not be displayed

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);
}

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...