Reputation: 388
The progress bar is created by the following code
bar = new JProgressBar(JProgressBar.VERTICAL);
bar.setEnabled(true);
bar.setBackground(Color.YELLOW);
bar.setForeground(Color.GREEN);
bar.setStringPainted(true);
getReflectedComponent().setLayout(new BorderLayout());
getReflectedComponent().add(bar, BorderLayout.CENTER);
Note that getReflectedComponent() returns a JComponent. In another method the displayed String the max value and the current value are manipulated, not more.
I really have no idea why this very strange grey stripes are displayed at the top. If I display the progress bar horizontally they are not there...
Upvotes: 3
Views: 1094
Reputation: 205865
Also consider a custom ProgressBarUI
, mentioned here and shown here.
Upvotes: 2
Reputation: 47607
I don't observe your problem with your code so it must come from something else that you are not showing us (one more argument to provide an SSCCE)
Here is an example to get yourself started:
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
public class TestScrollbars {
protected void initUI() {
final JFrame frame = new JFrame();
frame.setTitle(TestScrollbars.class.getSimpleName());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JProgressBar bar = new JProgressBar(JProgressBar.VERTICAL);
bar.setEnabled(true);
bar.setBackground(Color.YELLOW);
bar.setForeground(Color.GREEN);
bar.setStringPainted(true);
bar.setString("2000 g");
bar.setValue(65);
frame.setLayout(new BorderLayout());
frame.add(bar, BorderLayout.CENTER);
frame.setSize(500, 400);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new TestScrollbars().initUI();
}
});
}
}
And the resulting image (where progress bar is correctly displaying the chosen colors):
Upvotes: 3