Search code examples
javaswingjprogressbarnimbus

JProgressBar displaying weird orang wave


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?


Solution

  • I didn't look deep into it, but it might be a bug of Nimbus LaF.
    Anyway, in order for the orange blocks to stop moving (when its value is set to 100), you also seem to need to call:

    prog.setIndeterminate(false);
    

    If you want to "automate" this, you could subclass JProgressBar, e.g.:

    prog = new JProgressBar(0, 100) {
        public void setValue(int newValue) {
            super.setValue(newValue);
            if (newValue >= this.getMaximum()) {
                this.setIndeterminate(false);
            }
        }
    };
    prog.setValue(0);
    ...