Solved

Removing and adding Images (JAVA)

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java DateChooser? 3 36
Problem to picture file 20 50
maven module vs maven project 3 23
Chrome and Firefox Java 5 31
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

770 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