2017-08-14 31 views
0

我已经使用JLayer来装饰GUI,每秒都会更改背景颜色。这里是图像。使用JLayer的GUI

enter image description here

在此图像中,你可以看到出现在计时器的蓝色和黄色线。我意识到这些行出现是因为文本在文本区域中发生了变化,当文本区域中显示新的表达式时,会发生类似的情况。

如何删除这些行?

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(); 

    } 

} 

在此先感谢!

+2

为什么不使用'JLabel'代替? – trashgod

+0

谢谢!它的工作 – user007

+0

你可以[回答你自己的问题](http://meta.stackoverflow.com/q/17463/163188)。 – trashgod

回答

0

而不是使用JTextField的我用的JLabel通过trashgod的建议。