• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
{
}
 
Sheriff
Posts: 21459
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read Concurrency in Swing.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!