繁体   English   中英

Java swing BasicTextFieldUI绘画问题

[英]Java swing BasicTextFieldUI painting ISSUE

我正在一个项目中,我需要更改JTextFields样式 扩展BasicTextFieldUI ,并覆盖了paintSafely方法,但是,当它绘制组件时,它会绘制一个边框 (即使border设置为null )。 我尝试查看BasicTextUI类的内部,以查看可以绘制该边框的内容,但没有找到任何东西。

题,

为什么此代码将在组件周围创建边框?

这是我的代码:

public class CustomTextField extends BasicTextFieldUI{

    int borderThickness, edgeRoundness;

    @Override
    protected void paintSafely(Graphics g) {

        JComponent c = (JComponent)this.getComponent();
        Graphics2D g2 = (Graphics2D)g;
        g2.setColor(c.getBackground());

        borderThickness = 2;
        edgeRoundness = 20;

        g2.setColor(c.getForeground());
        g2.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), edgeRoundness+5, edgeRoundness+5);
        g2.drawRoundRect(0, 0, c.getWidth(), c.getHeight(), edgeRoundness+5, edgeRoundness+5);

        g2.setColor(c.getBackground());
        g2.fillRoundRect(borderThickness, borderThickness, c.getWidth()-(int)(borderThickness*2.5), c.getHeight()-(int)(borderThickness*2.5), edgeRoundness, edgeRoundness);
        g2.drawRoundRect(borderThickness, borderThickness, c.getWidth()-(int)(borderThickness*2.5), c.getHeight()-(int)(borderThickness*2.5), edgeRoundness, edgeRoundness);


        super.paintSafely(g);
    }

}

可能是什么错误? 是否有其他方法可用来喷涂组件?

在此处输入图片说明

我在这篇文章中找到了答案! 看来,通过将border设置为null ,我对PLAF说过要使用它自己的border。 摆动JTextField怎么去除边框?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM