本文介绍了如何在一个JFrame中多次添加一个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图多次进行一次图像显示。这是我的代码的一部分:
I am trying to make one image display multiple times. Here's part of my code:
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(30, 30, 800, 600);
JLabel blue = new JLabel(new ImageIcon("blue.jpg"));
JLabel green = new JLabel(new ImageIcon("green.jpg"));
window.add(blue);
window.add(green);
window.add(blue);
window.setLayout(new GridLayout(3, 3));
window.setVisible(true);
不幸的是,创建的只是每种图像。我做错了什么?
Unfortunately what is created is just one image of each kind. What am I doing wrong?
推荐答案
你必须创建9个单独的 JLabel
s填充3 x 3网格。你不能重复使用Swing组件。
You have to create 9 separate JLabel
s to fill a 3 x 3 grid. You cannot reuse Swing components.
你可以只创建一次蓝色图像图标和绿色图像。
You can just create the blue image icon and the green image icon one time.
这篇关于如何在一个JFrame中多次添加一个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!