0

I am using JProgressBar to display a progress bar on my frame. The progress bar is set to indeterminate mode as i dont know when the task will end. Instead of displaying the normal progress bar a wierd orange wave is displayed.
1

The wave keeps moving when the task is running. After it has ended the value is set to 100 and it displays it in the form or orange blocks(which are also moving!). I am using the following code to display the progress bar

Container content = this.getContentPane();
content.setLayout(null);    
prog = new JProgressBar(0, 100);
prog.setValue(0);
prog.setStringPainted(true);
Dimension preferredSize;
preferredSize=new Dimension();
preferredSize.width=300;
preferredSize.height=15;
prog.setPreferredSize(preferredSize);
content.add(prog);
Insets insets = content.getInsets();
Dimension size;
size = prog.getPreferredSize();
prog.setBounds(30+insets.left, 180+insets.top, size.width, size.height);

How do i change it back to the normal progress bar?

4

1 回答 1

2

我没有深入研究它,但它可能是 Nimbus LaF 的错误。
无论如何,为了让橙色块停止移动(当它的值设置为 100 时),您似乎还需要调用:

prog.setIndeterminate(false);

如果你想“自动化”这个,你可以继承 JProgressBar,例如:

prog = new JProgressBar(0, 100) {
    public void setValue(int newValue) {
        super.setValue(newValue);
        if (newValue >= this.getMaximum()) {
            this.setIndeterminate(false);
        }
    }
};
prog.setValue(0);
...
于 2013-06-05T13:05:21.860 回答