File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Trying to add Image Icons to a Gui one at a time but they all add together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Trying to add Image Icons to a Gui one at a time but they all add together" Watch "Trying to add Image Icons to a Gui one at a time but they all add together" New topic
Author

Trying to add Image Icons to a Gui one at a time but they all add together

Mark McG
Greenhorn

Joined: Mar 24, 2012
Posts: 2
Hi folks,

I have the following code.

Basically what I am trying to do is add each of the 4 labels (Which contain an image icon of a flag) to a GUI.

I want one flag added, a break for a couple of seconds, then a second one added and so on.

At the moment, nothing is happening for about 30 seconds and then they all appear on the GUI at once. When I change the code to add buttons as oppose to labels with image icons, they are added one at a time the way I want it to be. Therefore I know the code does work, but dosnt seem to work for labels/labels with image icons.

Can someone advise as to where they think I could be going wrong?

Thanks,
Mark






ImageIcon FranceFlagIcon = new ImageIcon("FranceFlagPic.jpg");
Image FranceFlagImage = FranceFlagIcon.getImage().getScaledInstance(80, 100, Image.SCALE_SMOOTH);
FranceFlagIcon.setImage(FranceFlagImage);

ImageIcon IrelandFlagIcon = new ImageIcon("IrelandFlagPic.jpg");
Image IrelandFlagImage = IrelandFlagIcon.getImage().getScaledInstance(80, 100, Image.SCALE_SMOOTH);
IrelandFlagIcon.setImage(IrelandFlagImage);

ImageIcon EnglandFlagIcon = new ImageIcon("EnglandFlagPic.jpg");
Image EnglandFlagImage = EnglandFlagIcon.getImage().getScaledInstance(80, 100, Image.SCALE_SMOOTH);
EnglandFlagIcon.setImage(EnglandFlagImage);

ImageIcon SpainFlagIcon = new ImageIcon("SpainFlagPic.jpg");
Image SpainFlagImage = SpainFlagIcon.getImage().getScaledInstance(80, 100, Image.SCALE_SMOOTH);
SpainFlagIcon.setImage(SpainFlagImage);


JLabel EnglandFlagLabel = new JLabel(EnglandFlagIcon, JLabel.LEFT);
JLabel IrelandFlagLabel = new JLabel(IrelandFlagIcon, JLabel.LEFT);
JLabel FranceFlagLabel = new JLabel(FranceFlagIcon, JLabel.LEFT);
JLabel SpainFlagLabel = new JLabel(SpainFlagIcon, JLabel.LEFT);


try
{


add(SpainFlagLabel);
SpainFlagLabel.setBounds(10,50,100,100);

Thread.sleep(1500);

add(SpainFlagLabel);
SpainFlagLabel.setBounds(10,50,100,100);

Thread.sleep(1500);

add(SpainFlagLabel);
SpainFlagLabel.setBounds(10,50,100,100);

Thread.sleep(1500);

add(SpainFlagLabel);
SpainFlagLabel.setBounds(10,50,100,100);

Thread.sleep(1500);

}
catch(InterruptedException e)
{
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Read Concurrency in Swing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to add Image Icons to a Gui one at a time but they all add together