0

So in my program I set in the beginning a JLabel to it so now an image is on it. Now I need to remove that JLabel and put a new one instead of it. So I did:

frame.remove(test_loadingJL);
frame.add(test_lockScreenJL);

But when I look, it is still the first image and it doesn't update until I resize the actual window manually. Is there a way to update the frame so I don't have to do that?

Wiz Gamin
  • 29
  • 3

3 Answers3

0

This should work frame.revalidate()

Ramesh Kotha
  • 8,266
  • 17
  • 66
  • 90
0

Your Choices:

 1.SwingUtilities.updateComponentTreeUI(name of Component(in your example is frame)

SwingUtilities.updateComponentTreeUI(frame);

2.frame.dispose();

frame.setVisible(true);

3.revalidate();

  revalidate();//<------------needed when add/remove components
  repaint();//sometimes needed also, sometimes not

Also check this link possible dublicate question same question here

These should work

Community
  • 1
  • 1
crAlexander
  • 376
  • 1
  • 2
  • 12
0

Try calling frame.setVisible(true) before adding the components.

smiley
  • 491
  • 3
  • 14
  • 36