0

I don't know how to properly explain this, so here's a picture:

the bar

You can see quite a bit of the background around the green line, especially at the start and below the line. How can I fix this?

mKorbel
  • 109,525
  • 20
  • 134
  • 319

2 Answers2

0

Your probably need to setBorderPainted to false. Refer http://docs.oracle.com/javase/8/docs/api/javax/swing/JProgressBar.html#setBorderPainted-boolean-

Vinod Jayachandran
  • 3,726
  • 8
  • 51
  • 88
0

The spaces / border visible on your screenshot is just the spacing of the parent panel, it is not the border of the JProgressBar.

For example you will see no borders around the progress bar in this example:

final JFrame f = new JFrame("Test");
final JProgressBar pb = new JProgressBar();
pb.setValue(50);
f.getContentPane().add(pb);
f.pack();
f.setVisible(true);

But if you use a JPanel as content pane with FlowLayout which has default 5 pixel horizontal and veritcal gap, you will see something like in your screenshot.

f.setContentPane(new JPanel(new FlowLayout()));

The spaces disappear if you use 0 spacing between components like this:

f.setContentPane(new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)));
icza
  • 389,944
  • 63
  • 907
  • 827
  • I'm not using a JPanel as the content pane, I'm using JFrame with absolute (null) layout for precise spacing. I also tried the 0 spacing between components, but that also gave the same result. – user3568178 May 29 '14 at 10:29
  • Then maybe you should post your code so we can identify what's wrong with it. Panel spacing is the most common reason, but if you use absolute positioning, then it's most likely your positioning logic. – icza May 29 '14 at 12:24