我正在对 JTextField 进行圆角处理,但字段圆角化后,边缘变得模糊,看起来不专业。
这是我用来舍入 JTextField 的代码。我正在扩展 JTextFiled 并更改 paintComponent
值。
//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);
}
最佳答案
在您的绘画方法中,您可以尝试对图形使用抗锯齿功能。
您可以在单独的 Graphics 对象上设置绘画属性:
Graphics2D g2d = (Graphics2D)g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// add painting logic
g2d.dispose();
关于java - 如何消除 JTextField 边缘的模糊?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65425098/