【发布时间】:2016-06-15 16:29:47
【问题描述】:
我有一个JLabel 数组,但是当一个图像附加到它并添加到我的容器中时,它不会出现在JFrame 上,这与非数组JLabels 不同。
我已尝试更改其覆盖的图像的不透明设置,将其设置为可见,并更改图像的布局。
我是 Stack Overflow 的新手,对 Swing 也比较陌生,因此欢迎所有批评。
import java.awt.Container;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Connect_Four extends JFrame {
private static final long serialVersionUID = 1L;
static JLabel[] piecelabel;
static int piececounter;
public Connect_Four(String title) {
piececounter = 0;
Container c = getContentPane();
piecelabel = createLabels();
piecelabel[piececounter].setIcon(new ImageIcon("F:/redpiece.jpg"));
piecelabel[piececounter].setBounds(0, (750 - (counter[0] * 100)), 135, 100);
c.add(piecelabel[piececounter]);
}
public JLabel[] createLabels() {
JLabel[] labels = new JLabel[42]; //used for connect 4 pieces
for (int i = 0; i < 42; i++) {
labels[i] = new JLabel();
}
return labels;
}
}
【问题讨论】:
-
这都是吗??????你有主线吗??你让事情可见吗?我什么也没看到
-
你的 USB 连接了吗?它在
F:端口上吗?还要避免使用null布局!请参阅:Why is it frowned upon to use null layout 和 Null Layout is Evil -
顺便说一句,如果您放置一次或 42 次,它的工作方式相同,请发布包含相关代码但仍显示您的问题的 minimal reproducible example,同样因为您是 Stack 的新手溢出取tour和how to ask