[英]Why doesn't the jlabel array show in the panel?
star
is my char[]
: star
是我的char[]
:
Label[] labels = new JLabel[20];
for (int k = 0; k < star.length; k++) {
labels[k] = new JLabel("x");
xPanel.add(labels[k]);
}
This works fine for me: 这对我来说很好:
public class MyFrame extends JFrame {
public static void main(final String[] args) {
final JFrame frame = new JFrame();
frame.setLayout(new FlowLayout());
final JLabel[] labels = new JLabel[20]; // replaced Label with JLabel
for (int k = 0; k < labels.length; k++) { // replaces star with labels
labels[k] = new JLabel("x");
frame.add(labels[k]);
}
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
and the result (after frame resizing is): 结果(在调整帧大小之后):
panel.updateUI();
您必须使用此方法来更新jlabel数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.