Issue regarding dynamically loading Images in loop using Java Swing

前端 未结 1 744
梦谈多话
梦谈多话 2021-01-22 19:02
public String[] imagesArray = {Images.firstImage, Images.secondImage};

String imagesPath = \"/testproject/images/\";
 for(int i = 0; i

        
相关标签:
1条回答
  • 2021-01-22 19:26

    The problem is most likely the asynchronous loading nature of using an ImageIcon to load the original images.

    If that is the problem:

    1. There is an easy way to test it. Add the orignalImageIcon to the button and see if they all appear.
    2. There is an easy way to fix it. Load the images using ImageIO.read(URL) - a method that will block until the image is completely loaded.
    0 讨论(0)
提交回复
热议问题