Solved

Removing and adding Images (JAVA)

Posted on 2007-04-09
1
174 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
1 Comment
 
LVL 92

Accepted Solution

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

should be:

                  imgPanel.revalidate();
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Facing this issue for maven proxy setting 2 21
Adding multiple JVM environments to RedHat 6 7 49
java example issue 5 26
Problem to Office 1 16
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

821 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