tags:

views:

138

answers:

2

I do understand that to create a title border, you do something like:

BorderFactory.createTitledBorder("  Your Title  ");

However this creates a rectangle border whereas I need a rectangle with curved corners.

Now from what I understand you can create your own custom border by:

class CustomBorder implements Border
{
  ...
}

The problem is that I'm not sure how to write the code that overrides the method:

public void paintBorder(Component component, Graphics g, int x, int y, int width, int height)

Or better yet, is there a way to do it without implementing your own Border class? And if not, how would you write that custom Title Border? I'm ok with drawing a rectangle with rounded corners, but how do you do it so that there's space for the label too?

A: 

Done.

2nd result for Google: java swing rounded border

mcandre
You didn't read the question ;) How do you add the title to the border, so that the title isn't overlayed on the border (ie. you can read it).
Stephane Grenier
+2  A: 

It is possible to create a title border with rounded edges without implementing your own Border class. Simply pass a rounded border to TitledBorder's constructor. Try the following:

LineBorder roundedLineBorder = new LineBorder(Color.black, 5, true);
TitledBorder roundedTitledBorder = new TitledBorder(roundedLineBorder, "Title");
EMurnane