gpt4 book ai didi

Java Swing 幽灵/双重组件?

转载 作者:行者123 更新时间:2023-12-02 05:41:34 26 4
gpt4 key购买 nike

(编辑)此问题已解决 - 请参阅答案。

我遇到了一个我以前从未见过的 Java/Swing 和 Netbeans 的不幸问题。我在 Netbeans 中设计了一个基本的纸牌游戏形式,它看起来运行得很好。下图: /image/IcZ7F.png

请注意左下角的导航器 View ,它清楚地列出了底部面板中的所有组件。

当我实际运行游戏时,乍一看似乎还不错...... /image/SNKK8.png

...但是当您最大化窗口时,您突然会无缘无故地看到面板内容的副本。 /image/y0LhY.png

这种重叠不仅令人困惑,还会导致按钮事件指向错误的组件,从而使游戏完全无法玩。默认情况下,会显示正确的聊天文本区域,但是当您单击它来聚焦时,它会突然将空白文本区域也带到前面,从而有效地隐藏了聊天文本区域。

此问题也会影响顶部面板,其中有本应没有文本的 jLabels 虚拟重复项(如右侧所示)。

是什么原因导致此问题以及如何解决?我在导航器中找不到面板的重复项,清理和构建不起作用,甚至自动生成的代码也没有显示向窗口添加两个文本区域的提示。

非常感谢您的帮助!

(编辑)相关自动生成的 initComponents 代码如下。我从未接触过这段代码,因为它是由 Netbeans 自动生成的。

// Variables declaration - do not modify                     
private javax.swing.JLabel bC1;
private javax.swing.JLabel bC2;
private javax.swing.JLabel bC3;
private javax.swing.JLabel bC4;
private javax.swing.JLabel bC5;
private javax.swing.JLabel bC6;
private javax.swing.JLabel bC7;
private javax.swing.JSpinner betSpinner;
private javax.swing.JButton btnBet;
private javax.swing.JButton btnPass;
private javax.swing.JPanel gamePanel;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel lC1;
private javax.swing.JLabel lC2;
private javax.swing.JLabel lC3;
private javax.swing.JLabel lC4;
private javax.swing.JLabel lC5;
private javax.swing.JLabel lC6;
private javax.swing.JLabel lC7;
private javax.swing.JPanel playingField;
private javax.swing.JPanel plrBottom;
private javax.swing.JPanel plrLeft;
private javax.swing.JPanel plrRight;
private javax.swing.JPanel plrTop;
private javax.swing.JLabel rC1;
private javax.swing.JLabel rC2;
private javax.swing.JLabel rC3;
private javax.swing.JLabel rC4;
private javax.swing.JLabel rC5;
private javax.swing.JLabel rC6;
private javax.swing.JLabel rC7;
private javax.swing.JPanel statusPanel;
private javax.swing.JLabel tC1;
private javax.swing.JLabel tC2;
private javax.swing.JLabel tC3;
private javax.swing.JLabel tC4;
private javax.swing.JLabel tC5;
private javax.swing.JLabel tC6;
private javax.swing.JLabel tC7;
private javax.swing.JTextArea textAreaChat;
// End of variables declaration

private void initComponents() {

statusPanel = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
textAreaChat = new javax.swing.JTextArea();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
betSpinner = new javax.swing.JSpinner();
btnBet = new javax.swing.JButton();
btnPass = new javax.swing.JButton();
gamePanel = new javax.swing.JPanel();
plrRight = new javax.swing.JPanel();
rC1 = new javax.swing.JLabel();
rC2 = new javax.swing.JLabel();
rC3 = new javax.swing.JLabel();
rC4 = new javax.swing.JLabel();
rC5 = new javax.swing.JLabel();
rC6 = new javax.swing.JLabel();
rC7 = new javax.swing.JLabel();
plrBottom = new javax.swing.JPanel();
bC1 = new javax.swing.JLabel();
bC2 = new javax.swing.JLabel();
bC3 = new javax.swing.JLabel();
bC4 = new javax.swing.JLabel();
bC5 = new javax.swing.JLabel();
bC6 = new javax.swing.JLabel();
bC7 = new javax.swing.JLabel();
plrLeft = new javax.swing.JPanel();
lC1 = new javax.swing.JLabel();
lC2 = new javax.swing.JLabel();
lC3 = new javax.swing.JLabel();
lC4 = new javax.swing.JLabel();
lC5 = new javax.swing.JLabel();
lC6 = new javax.swing.JLabel();
lC7 = new javax.swing.JLabel();
plrTop = new javax.swing.JPanel();
tC1 = new javax.swing.JLabel();
tC2 = new javax.swing.JLabel();
tC3 = new javax.swing.JLabel();
tC4 = new javax.swing.JLabel();
tC5 = new javax.swing.JLabel();
tC6 = new javax.swing.JLabel();
tC7 = new javax.swing.JLabel();
playingField = new javax.swing.JPanel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

statusPanel.setPreferredSize(new java.awt.Dimension(0, 180));

textAreaChat.setEditable(false);
textAreaChat.setColumns(20);
textAreaChat.setRows(5);
jScrollPane1.setViewportView(textAreaChat);

jButton1.setText("Send");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel1.setText("Betting");

btnBet.setText("Bet");
btnBet.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBetActionPerformed(evt);
}
});

btnPass.setText("Pass");
btnPass.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPassActionPerformed(evt);
}
});

javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(statusPanelLayout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(statusPanelLayout.createSequentialGroup()
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnBet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(betSpinner, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnPass, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())))))
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(betSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnBet)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPass))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addGap(27, 27, 27))
);

getContentPane().add(statusPanel, java.awt.BorderLayout.PAGE_END);

gamePanel.setLayout(new java.awt.BorderLayout());

rC1.setText("jLabel1");
rC1.setMaximumSize(new java.awt.Dimension(14, 34));
rC1.setMinimumSize(new java.awt.Dimension(14, 34));
rC1.setPreferredSize(new java.awt.Dimension(14, 34));

rC2.setText("jLabel1");
rC2.setMaximumSize(new java.awt.Dimension(14, 34));
rC2.setMinimumSize(new java.awt.Dimension(14, 34));
rC2.setPreferredSize(new java.awt.Dimension(14, 34));

rC3.setText("jLabel1");
rC3.setMaximumSize(new java.awt.Dimension(14, 34));
rC3.setMinimumSize(new java.awt.Dimension(14, 34));
rC3.setPreferredSize(new java.awt.Dimension(14, 34));

rC4.setText("jLabel1");
rC4.setMaximumSize(new java.awt.Dimension(14, 34));
rC4.setMinimumSize(new java.awt.Dimension(14, 34));
rC4.setPreferredSize(new java.awt.Dimension(14, 34));

rC5.setText("jLabel1");
rC5.setMaximumSize(new java.awt.Dimension(14, 34));
rC5.setMinimumSize(new java.awt.Dimension(14, 34));
rC5.setPreferredSize(new java.awt.Dimension(14, 34));

rC6.setText("jLabel1");
rC6.setMaximumSize(new java.awt.Dimension(14, 34));
rC6.setMinimumSize(new java.awt.Dimension(14, 34));
rC6.setPreferredSize(new java.awt.Dimension(14, 34));

rC7.setText("jLabel1");
rC7.setMaximumSize(new java.awt.Dimension(14, 34));
rC7.setMinimumSize(new java.awt.Dimension(14, 34));
rC7.setPreferredSize(new java.awt.Dimension(14, 34));

javax.swing.GroupLayout plrRightLayout = new javax.swing.GroupLayout(plrRight);
plrRight.setLayout(plrRightLayout);
plrRightLayout.setHorizontalGroup(
plrRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(plrRightLayout.createSequentialGroup()
.addGroup(plrRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(rC1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rC2, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rC3, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rC4, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rC5, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rC6, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rC7, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
plrRightLayout.setVerticalGroup(
plrRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(plrRightLayout.createSequentialGroup()
.addGap(5, 5, 5)
.addComponent(rC1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rC2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rC3, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rC4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rC5, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rC6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rC7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

gamePanel.add(plrRight, java.awt.BorderLayout.LINE_END);

bC1.setText("jLabel1");

bC2.setText("jLabel1");

bC3.setText("jLabel1");

bC4.setText("jLabel1");

bC5.setText("jLabel1");

bC6.setText("jLabel1");

bC7.setText("jLabel1");

javax.swing.GroupLayout plrBottomLayout = new javax.swing.GroupLayout(plrBottom);
plrBottom.setLayout(plrBottomLayout);
plrBottomLayout.setHorizontalGroup(
plrBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(plrBottomLayout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(bC1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bC2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bC3, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bC4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bC5, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bC6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bC7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
plrBottomLayout.setVerticalGroup(
plrBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(plrBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bC1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bC2, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bC3, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bC4, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bC5, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bC6, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bC7, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
);

gamePanel.add(plrBottom, java.awt.BorderLayout.PAGE_END);

lC1.setText("jLabel1");
lC1.setMaximumSize(new java.awt.Dimension(14, 34));
lC1.setMinimumSize(new java.awt.Dimension(14, 34));
lC1.setPreferredSize(new java.awt.Dimension(14, 34));

lC2.setText("jLabel1");
lC2.setMaximumSize(new java.awt.Dimension(14, 34));
lC2.setMinimumSize(new java.awt.Dimension(14, 34));
lC2.setPreferredSize(new java.awt.Dimension(14, 34));

lC3.setText("jLabel1");
lC3.setMaximumSize(new java.awt.Dimension(14, 34));
lC3.setMinimumSize(new java.awt.Dimension(14, 34));
lC3.setPreferredSize(new java.awt.Dimension(14, 34));

lC4.setText("jLabel1");
lC4.setMaximumSize(new java.awt.Dimension(14, 34));
lC4.setMinimumSize(new java.awt.Dimension(14, 34));
lC4.setPreferredSize(new java.awt.Dimension(14, 34));

lC5.setText("jLabel1");
lC5.setMaximumSize(new java.awt.Dimension(14, 34));
lC5.setMinimumSize(new java.awt.Dimension(14, 34));
lC5.setPreferredSize(new java.awt.Dimension(14, 34));

lC6.setText("jLabel1");
lC6.setMaximumSize(new java.awt.Dimension(14, 34));
lC6.setMinimumSize(new java.awt.Dimension(14, 34));
lC6.setPreferredSize(new java.awt.Dimension(14, 34));

lC7.setText("jLabel1");
lC7.setMaximumSize(new java.awt.Dimension(14, 34));
lC7.setMinimumSize(new java.awt.Dimension(14, 34));
lC7.setPreferredSize(new java.awt.Dimension(14, 34));

javax.swing.GroupLayout plrLeftLayout = new javax.swing.GroupLayout(plrLeft);
plrLeft.setLayout(plrLeftLayout);
plrLeftLayout.setHorizontalGroup(
plrLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(plrLeftLayout.createSequentialGroup()
.addGroup(plrLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lC1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lC2, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lC3, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lC4, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lC5, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lC6, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lC7, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
plrLeftLayout.setVerticalGroup(
plrLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(plrLeftLayout.createSequentialGroup()
.addGap(5, 5, 5)
.addComponent(lC1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lC2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lC3, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lC4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lC5, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lC6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lC7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

gamePanel.add(plrLeft, java.awt.BorderLayout.LINE_START);

tC1.setText("jLabel1");

tC2.setText("jLabel1");

tC3.setText("jLabel1");

tC4.setText("jLabel1");

tC5.setText("jLabel1");

tC6.setText("jLabel1");

tC7.setText("jLabel1");

javax.swing.GroupLayout plrTopLayout = new javax.swing.GroupLayout(plrTop);
plrTop.setLayout(plrTopLayout);
plrTopLayout.setHorizontalGroup(
plrTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(plrTopLayout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(tC1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tC2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tC3, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tC4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tC5, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tC6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tC7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
plrTopLayout.setVerticalGroup(
plrTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(plrTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tC1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tC2, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tC3, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tC4, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tC5, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tC6, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tC7, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
);

gamePanel.add(plrTop, java.awt.BorderLayout.PAGE_START);

javax.swing.GroupLayout playingFieldLayout = new javax.swing.GroupLayout(playingField);
playingField.setLayout(playingFieldLayout);
playingFieldLayout.setHorizontalGroup(
playingFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
playingFieldLayout.setVerticalGroup(
playingFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);

gamePanel.add(playingField, java.awt.BorderLayout.CENTER);

getContentPane().add(gamePanel, java.awt.BorderLayout.CENTER);

pack();
}// </editor-fold>

最佳答案

我已找到并解决了该问题;在困惑的构造函数中,initComponents() 被调用了两次。我深感羞愧。

关于Java Swing 幽灵/双重组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24467597/

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