gpt4 book ai didi

java - JLabel的显示数组

转载 作者:行者123 更新时间:2023-12-01 22:37:53 24 4
gpt4 key购买 nike

用于在 JPanel 中显示 10 个标签我使用 Netbeans for Java 使用了以下代码。没有得到任何输出。 JPanel布局设置为null布局。

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JLabel[] labels = new JLabel[10];
for(int i=0; i<9; i++){
labels[i] = new JLabel("Label Name " + i);
p1.add(labels[i]);}
}

最佳答案

您需要调用validate向框架对象添加子组件后的方法。

The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.

关于java - JLabel的显示数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26627083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com