PDStat
PDStat

Reputation: 5825

JProgressBar background colour

I am trying to set the foreground colour of progress bars to green, and the background colour to yellow, I am doing the following

  JProgressBar pb = new JProgressBar(0, 100);
  pb.setBackground(Color.YELLOW);
  pb.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
  pb.setForeground(Color.GREEN.darker());
  pb.setOpaque(true);
  pb.setStringPainted(true);
  pb.setPreferredSize(new Dimension(pb.getPreferredSize().width, 16));

I expected the bar to be yellow, instead the colour behind the bar is yellow. See below (I have tried the UIManager approach as well)

enter image description here

EDIT: It looks like it's the Windows L&F that's causing the issue

Upvotes: 1

Views: 387

Answers (2)

Java Man
Java Man

Reputation: 1860

progressBar.setStringPainted(true);
progressBar.setForeground(Color.GREEN.darker());
progressBar.background(Color.YELLOW);
progressBar.setString("50%");

Try this..

Upvotes: 0

Niels Bech Nielsen
Niels Bech Nielsen

Reputation: 4859

Out of curiosity would it improve it if you setopaque = false;

Upvotes: 1

Related Questions