简体   繁体   中英

GUI using JLayer

I have used JLayer to decorate GUI the background color will be changed every second. 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。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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