5

I'm working on a GUI in Java, and I'm trying to give rounded corners to my borders.

JPanel recentProjectsPanel = new JPanel();
    recentProjectsPanel.setLayout(new BorderLayout());
    recentProjectsPanel.setBackground(Color.red);
    recentProjectsPanel.setBorder(new LineBorder(Color.green, 15, true));

This is the output I get (don't mind the colors):

Failing Border GUI

Why do I get these red stripes in the corners? Any way to fix this?

casperOne
  • 72,334
  • 18
  • 180
  • 242
jeerome48
  • 411
  • 3
  • 8
  • 1
    For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson May 04 '12 at 11:01
  • 1
    Be certain to honor the [opacity](http://java.sun.com/products/jfc/tsc/articles/painting/index.html#props) property. – trashgod May 04 '12 at 11:09
  • If you look at the source code, the way the rounded corner border is painted is terrible...instead of setting a stroke and drawing a single rounded rectangle, successive rounded rectangles are drawn, which results in the above ugliness. – user1329572 May 04 '12 at 13:59

2 Answers2

3

You might use a variant of the TextBubbleBorder instead.

Community
  • 1
  • 1
Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
2

Have a look at this

Java - rounded corner panel with compositing in paintComponent

this has much information regarding same.

Community
  • 1
  • 1
Rahul Borkar
  • 2,724
  • 2
  • 22
  • 38