Atom Feed SITE FEED   ADD TO GOOGLE READER

Rounded Corners as a Swing Border

Rounded BordersIn order to get a desired effect in the Glazed Lists issues browser, I created a border with rounded corners, a la Web 2.0. Implementing the painting logic was tedious, but not particularly difficult -- there's a lot of "magic-numbers" Java2D code to write, such as offsetting by the stroke width and figuring out the stroke angles.

If you want your Swing app to look Web 2.0, please take RoundedBorder.java and contribute back your enhancements & fixes!
Why not using transparency and optimize border inset (width) ?
- background and foreground color could be transparent (new Color(0,0,0,0))
- using Pythagore to optimize border width :
public Insets getBorderInsets(Component c) {
int inset = radius - new Double(Math.sqrt(((radius-stroke)*(radius-stroke))/2)).intValue();
return new Insets(inset, inset, inset, inset);
}

Better is it ?

JC
There's no licence in the file.
The code is competely free with no warranty. You can use the file under your choice of the Mozilla License or LGPL.
Here's how to setup the rendering hints:

/** all icons are drawn in high quality */
public static final Map<RenderingHints.Key,Object> RENDERING_HINTS = new HashMap<RenderingHints.Key,Object>();
static {
RENDERING_HINTS.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}