1

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

PDStat
  • 5,513
  • 10
  • 51
  • 86

2 Answers2

1

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

Java Man
  • 1,854
  • 3
  • 21
  • 43
Niels Bech Nielsen
  • 4,777
  • 1
  • 21
  • 44
  • Unfortunately not, the yellow outline disappears in that case. I have a feeling it's something specific to using JIDE components, hmmmm – PDStat Jan 30 '14 at 15:04
0
progressBar.setStringPainted(true);
progressBar.setForeground(Color.GREEN.darker());
progressBar.background(Color.YELLOW);
progressBar.setString("50%");

Try this..

Java Man
  • 1,854
  • 3
  • 21
  • 43