开发者

Java - delete an ImageIcon?

开发者 https://www.devze.com 2023-03-04 16:40 出处:网络
Is there any way to easily delete an ImageIcon completely from the screen? I can\'t find one anywhere.

Is there any way to easily delete an ImageIcon completely from the screen? I can't find one anywhere.

ImageIcon image = new ImageIcon("candle.gif");
image.paintIcon(this, g, 150, 80)
开发者_C百科

For example, if I wanted to get rid of "image" later on when a button is pressed, what would be the appropriate code? (Not for the button, I know how to do that).


Don't reinvent the wheel. The easiest way to paint an Icon is to use a JLabel. The code would be something like:

ImageIcon icon = new ImageIcon(...);
JLabel label = new JLabel( icon );
panel.add( label );

If you don't want to display the icon anymore then in the ActionListener of your button you simple do:

label.setIcon( null );    
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号