我用JLayer来装饰图形用户界面,背景色每秒钟都会发生变化。这是图像。

在这张图片中,你可以看到定时器中出现的蓝色和黄色的线条。我意识到这些行的出现是因为文本区域中的文本正在发生变化,在文本区域中显示新表达式时也会发生类似的事情。
这些线条怎么才能被移除?
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();
}
}提前谢谢!
发布于 2017-08-18 11:34:32
我没有使用JTextField,而是按照垃圾神的建议使用了JLabel。
https://stackoverflow.com/questions/45680705
复制相似问题