JPanel removeAll doesn't get rid of previous components

前端 未结 2 1511
我在风中等你
我在风中等你 2020-12-19 00:07

I have a swing application in which I display images in a JPanel. If the app is unable to produce the image I want to remove the previous one from the JPanel and replace it

相关标签:
2条回答
  • 2020-12-19 00:48

    You can simply try calling :

    cdPanel.revalidate();
    cdPanel.repaint();   // This is required in some cases
    

    instead of

    cdPanel.validate();
    
    0 讨论(0)
  • 2020-12-19 01:01

    As you are dealing with unpredictable latency, use a SwingWorker to do the loading in the background, as shown here. The example uses pack() to resize the label to that of the image, but you may want to use a fixed-size grid and scale the images, as shown here.

    0 讨论(0)
提交回复
热议问题