【发布时间】:2018-11-28 17:13:30
【问题描述】:
我想在 JPanel 中动态添加 JLabels,就像我附加的图像一样。加载所有图像后,我需要选择一个图像,然后选择的图像应该出现在另一个 JPanel 中。我正在从包含路径的 ArrayList 中读取图像。
我在 JScrollPane 中将 Jpanel 与 GridLayout 一起使用,但结果与我想要的不一样。
这是我用来添加 Jlabels 的代码:
for(String file: files) {
JLabel JLabelPicture = new JLabel(new ImageIcon(file));
panel_images.add(JLabelPicture);
}
【问题讨论】:
-
“结果和我想要的不一样” 你能解释一下你看到的结果是什么吗?并将创建 GridLayout 和 JPanel 的代码添加到您的问题中。