有没有办法消除jtextfield边缘的模糊?

vd8tlhqk  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(334)

我正在圆化我的jtextfield,但圆化后的边缘模糊,看起来不专业。
这是我用来舍入jtextfield的代码。我正在扩展jtextfield并更改paintcomponenet值。

//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);
    }
k7fdbhmy

k7fdbhmy1#

在绘制方法中,可以尝试对图形使用抗锯齿。
可以在单独的图形对象上设置绘制属性:

Graphics2D g2d = (Graphics2D)g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// add painting logic
g2d.dispose();

相关问题