Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有什么方法可以轻松地从屏幕上完全删除 ImageIcon 吗?我在任何地方都找不到。
ImageIcon image = new ImageIcon("candle.gif"); image.paintIcon(this, g, 150, 80)
例如,如果我想稍后在按下按钮时摆脱“图像”,那么合适的代码是什么?(不是按钮,我知道该怎么做)。
不要重新发明轮子。绘制图标最简单的方法是使用 JLabel。代码将类似于:
ImageIcon icon = new ImageIcon(...); JLabel label = new JLabel( icon ); panel.add( label );
如果您不想再显示图标,那么在按钮的 ActionListener 中,您只需执行以下操作:
label.setIcon( null );