Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Removing and adding Images (JAVA)

Posted on 2007-04-09
1
Medium Priority
?
178 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 2000 total points
ID: 18879735
>                   imgPanel.repaint();

should be:

                  imgPanel.revalidate();
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

670 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