I need to create a rounded border on one side of a component only.
This code creates a rounded border:
new LineBorder(Color.RED, 3, true)
I have seen this thread which shows you how to create a matte border that can be used on one side of a component only, however a matte border isn't rounded.
Is it possible to have a rounded border on one side only?
Edit:
I have tried using compound border like this:
cell.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(borderColor, 3, true),
BorderFactory.createMatteBorder(0, 3, 0, 0, Color.black)));
But it doesn't work...
With the CSS border-radius property, you can give any element "rounded corners".
CSS Syntaxborder-top-left-radius: length|% [length|%]|initial|inherit; Note: If you set two values, the first one is for the top border, and the second one for the left border. If the second value is omitted, it is copied from the first. If either length is zero, the corner is square, not rounded.
Removing Border RadiusUse the . rounded-0 helper class to remove all of an elements radius or select by side or corner; e.g. . rounded-l-0 and . rounded-tr-0 .
You can override the method of LineBorder and draw all you need there From sources of LineBorder
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Color oldColor = g.getColor();
int i;
/// PENDING(klobad) How/should do we support Roundtangles?
g.setColor(lineColor);
for(i = 0; i < thickness; i++) {
if(!roundedCorners)
g.drawRect(x+i, y+i, width-i-i-1, height-i-i-1);
else
SET CLIP HERE TO DRAW ONLY NECESSARY PART
g.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, thickness, thickness);
}
g.setColor(oldColor);
}
LineBorder
only supports all corners rounded or not. A compound border (as the JavaDoc states) uses one border for the outside and one for the inside and thus does not distinguish between left/right or top/bottom.
I'm afraid you'd either have to write your own Border
implementation or look for one that's already made by someone else (external library).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With