Java 在JTextField的边缘是否有消除模糊的方法?
我正在圆化我的JTextField,但在圆化字段后,边缘模糊,看起来不专业 这是我用来取整JTextField的代码。我正在扩展JTextField并更改paintComponenet值Java 在JTextField的边缘是否有消除模糊的方法?,java,swing,graphics,Java,Swing,Graphics,我正在圆化我的JTextField,但在圆化字段后,边缘模糊,看起来不专业 这是我用来取整JTextField的代码。我正在扩展JTextField并更改paintComponenet值 //Rouding the field protected void paintComponent(Graphics g) { g.setColor(getBackground()); g.fillRoundRect(0, 0, getWidth()-1, get
//Rouding the field
protected void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15);
super.paintComponent(g);
}
protected void paintBorder(Graphics g) {
g.setColor(getForeground());
g.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15);
}
public boolean contains(int x, int y) {
if (shape == null || !shape.getBounds().equals(getBounds())) {
shape = new RoundRectangle2D.Float(0, 0, getWidth()-1, getHeight()-1, 15, 15);
}
return shape.contains(x, y);
}
在绘制方法中,可以尝试对图形使用抗锯齿 您可以在单独的图形对象上设置绘制属性:
Graphics2D g2d = (Graphics2D)g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// add painting logic
g2d.dispose();