【发布时间】:2014-10-26 12:03:34
【问题描述】:
我知道如何在单独的 JFrames 中显示图像。
public static void displayImage(BufferedImage img) {
JFrame f = new JFrame();
f.add(new JLabel(new ImageIcon(img)));
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
但我想要一种方法在单个 JFrame(或合适的元素)中显示所有图像,因此我可以使用两个按钮(“下一个”和“上一个”)在图像之间切换。
【问题讨论】:
-
使用
CardLayout..或单个JLabel来显示下一个/上一个.. 请参阅this answer 并向下滚动到许多图像了解更多想法。
标签: java swing jframe jpanel bufferedimage