简体   繁体   English

使用JLayer的GUI

[英]GUI using JLayer

I have used JLayer to decorate GUI the background color will be changed every second. 我已经使用JLayer来装饰GUI,背景颜色将每秒更改一次。 here is the image. 这是图像。

在此处输入图片说明

In this image you could see the blue and yellow line appearing in the timer. 在此图像中,您可以看到计时器中出现了蓝线和黄线。 I realized that these line are appearing because the text is changing in the text area similar thing happens when new expression is displayed in the text area. 我意识到出现这些行是因为文本在文本区域中发生了变化,当新的表达式显示在文本区域中时,也会发生类似的情况。

How these lines could be removed? 如何删除这些行?

class MyLayerUISubclass extends LayerUI<JComponent>{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public void paint(Graphics g, JComponent c){

        super.paint(g, c);

        Graphics2D g2 = (Graphics2D) g.create();

        int red = (int) (Math.random()*255);
        int green = (int) (Math.random()*255);
        int blue = (int) (Math.random()*255);

        Color startColor = new Color(red, green, blue);

        red = (int) (Math.random()*255);
        green = (int) (Math.random()*255);
        blue = (int) (Math.random()*255);

        Color endColor = new Color(red, green, blue);

        int w = c.getWidth();
        int h = c.getHeight();
        g2.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, .5f));
        g2.setPaint(new GradientPaint(0, 0, startColor, 0, h, endColor));
        g2.fillRect(0, 0, w, h);

        g2.dispose();

    }

 }

thanks in advance! 提前致谢!

我没有使用JTextField,而是使用了垃圾桶建议的JLabel。

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

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