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