1
import javax.swing.*; { JFrame ShoppingMarket=new JFrame(); { ShoppingMarket.add(new JLabel(new ImageIcon("C:\\Users\\admin \\Desktop\\The Da Vinci Code.jpg"))); ShoppingMarket.pack(); ShoppingMarket.setVisible(true); } ShoppingMarket.add(new JLabel(new ImageIcon("C:\\Users\\admin \\Desktop\\Angels And Demons.jpg"))); ShoppingMarket.pack(); ShoppingMarket.setVisible(true); } 

It doesn't clear the screen on closing the first window. so both pictures are shown on screen.

1 Answer 1

5

Instead of adding a new JLabel to the frame, store the original to a field of the enclosing class. Then you can simply call label.setIcon(theNewIcon), where I'm assuming the field is named label. See the relevant documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

ImageIcon.getImage().flush(); should be important for resources disposed loosely on HDD

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.