Solved

Removing and adding Images (JAVA)

Posted on 2007-04-09
1
170 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now