我只需要在组件的一侧上创建一个圆角边框。
此代码创建一个圆角边框:
new LineBorder(Color.RED, 3, true)
我看过this thread它向您展示了如何创建只能在组件的一侧使用的磨砂边框,但磨砂边框不是圆形的。
是否可以只在一侧有圆角边框?
编辑:
我试过像这样使用复合边框:
cell.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(borderColor, 3, true),
BorderFactory.createMatteBorder(0, 3, 0, 0, Color.black)));
但它不起作用......
最佳答案
你可以覆盖 LineBorder 的方法并在那里绘制所有你需要的 来自 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);
}
关于java - 仅在一侧的圆角边框 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7040812/