当我尝试制作圆角矩形时,出现非常像素化的边角。有什么方法可以使它们变得平滑?如何平滑圆角矩形中的拐角,Swing?
下面是一个图像(注意拐角):
这里是我子类并覆盖paint方法(带有像素化角落)按钮的代码:
public class ControlButton extends JButton {
public final static Color BUTTON_TOP_GRADIENT = new Color(176, 176, 176);
public final static Color BUTTON_BOTTOM_GRADIENT = new Color(156, 156, 156);
public ControlButton(String text) {
setText(text);
}
public ControlButton() {
}
@Override
protected void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D)g.create();
g2.setPaint(new GradientPaint(
new Point(0, 0),
BUTTON_TOP_GRADIENT,
new Point(0, getHeight()),
BUTTON_BOTTOM_GRADIENT));
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 20, 20);
g2.dispose();
}
}
RenderingHints中,设置反锯齿上。 – arynaq
看看这个问题的答案 - http://stackoverflow.com/questions/15025092/border-with-rounded-corners-transparency – Ciphor