當我嘗試製作圓角矩形時,出現非常像素化的邊角。有什麼方法可以使它們變得平滑?如何平滑圓角矩形中的拐角,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