我可以创建带有图像列表的 JFrame 吗?

Can I create a JFrame with list of images?

我想在 Java 中创建一个 JFrame,其中包含从 Web 下载的图像列表。我会将它们放在彼此下方的 JFrame 中,并在图像的一侧放置文本,我该怎么做?

我做了什么:

    Image image = null;
    ArrayList<JLabel> lb = new ArrayList<JLabel>(); // list of images 

    JFrame frame = new JFrame();
    frame.setSize(300, 300);

    lb.add(...);

    //...

    frame.add(lb);

    frame.setVisible(true);

您可以使用 GridLayout

ArrayList<JLabel> lb=new ArrayList<JLabel>(); //list of images

JFrame frame = new JFrame();
frame.setLayout(new GridLayout(rows,columns));//In your case (lb.size,2)
frame.setSize(300, 300);

//Now You need to Iterate through the List.

for(JLabel label:lb){
  frame.add(lb);  //Adding each image to the Frame
  frame.add(textLabel); //This is the text you want in side of image
 }

frame.setVisible(true);

根据@Jean-François Savard 的建议,下面是您将获得的示例