【发布时间】:2012-04-04 20:49:14
【问题描述】:
我使用类来制作圆角边框
班级是:
public class RoundedBorder implements Border {
int radius;
public RoundedBorder(int radius) {
this.radius = radius;
}
@Override
public Insets getBorderInsets(Component c) {
return new Insets(this.radius/2, this.radius, this.radius/2, this.radius);
}
@Override
public boolean isBorderOpaque() {
return true;
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D graphics = (Graphics2D) g;
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.drawRoundRect(x,y,width-1,height-1,radius,radius);
}
}
对于我使用的按钮:
JTextField login_nickname = new JTextField();
login_nickname.setBorder(new RoundedBorder(10));
login_nickname.setPreferredSize(new Dimension(150, 25));
它工作得很好,但我想删除角落圆角边框之外未使用的背景,我附上图片来解释我的意思,
谢谢
【问题讨论】:
-
1) "i used class to make.." 请使用 shift 键在句首以及单词'I'处制作大写字母.这样做有助于读者。 2) 为了尽快获得更好的帮助,请发帖SSCCE。
标签: java swing rounded-corners