Solved

Removing and adding Images (JAVA)

Posted on 2007-04-09
1
177 Views
Last Modified: 2010-03-31
I have the following in main:

            JFrame f = new JFrame();
            f.addWindowListener(new WindowAdapter()
            {
                  public void windowClosing(WindowEvent e)
                  {
                        System.exit(0);
                  }
            });
            f.setSize(600, 600);
            f.setLayout(new FlowLayout());

            JPanel imgPanel =  new JPanel();
            imgPanel.add(new JLabel(new ImageIcon("compass.jpg")));
            f.add(imgPanel);
            
            f.setVisible(true);
            /***********/
            try{Thread.sleep(3000);}catch(Exception e){}
                  imgPanel.removeAll();
                  f.repaint();
                  
                  try{Thread.sleep(3000);}catch(Exception e){}
                  imgPanel.add(new JLabel(new ImageIcon("compass.jpg")));
                  f.add(imgPanel);
                  imgPanel.repaint();
                  f.repaint();


=========================
I want to remove and add the image again.
The code above removes the image BUT does not add it again.

Any Ideas
0
Comment
Question by:hamadqtr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 18879735
>                   imgPanel.repaint();

should be:

                  imgPanel.revalidate();
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question