在 JPanel 上显示 jpg 图像
如何在 JPanel 中显示存储在 arraylist 中的 jpg 图像? 我无法在 JPanel 中显示 jpg 文件。
String[] pictureFile = {"A.jpg","B.jpg","C.jpg"};
List<String> picList1 = Arrays.asList(pictureFile);
Collections.shuffle(picList1);
ImageIcon icon = new ImageIcon("picList1.get(0)");
JLabel label1 = new JLabel();
label1.setIcon(icon);
JPanel panel = newJPanel;
panel.add(label);
How can I display jpg image which I stored in arraylist in JPanel?
Im not able to display the jpg files in the JPanel.
String[] pictureFile = {"A.jpg","B.jpg","C.jpg"};
List<String> picList1 = Arrays.asList(pictureFile);
Collections.shuffle(picList1);
ImageIcon icon = new ImageIcon("picList1.get(0)");
JLabel label1 = new JLabel();
label1.setIcon(icon);
JPanel panel = newJPanel;
panel.add(label);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应将对数组的调用放在引号中。
相反,您应该尝试以下操作:
You should not put the call to the array in quotes.
Instead, you should try the following:
问题出在
It'sterpreting the string as a file name 行中。您只需取消引用
picList1.get(0)
位即可。The problem is in the line
It's interpreting the string as a file name. You should just need to unquote the
picList1.get(0)
bit.