我在Card Layout中的开关面板有问题。我创建卡布局,然后向其中添加一些面板。当我尝试从jLabel2切换面板文本时,没有出现,但我认为该面板已更改。
panelGlowny = new javax.swing.JLayeredPane();
losowaniePanel = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
test = new javax.swing.JButton();
.....
panelGlowny.setLayout(new java.awt.CardLayout());
jLabel2.setText("Losowanie Panel");
javax.swing.GroupLayout losowaniePanelLayout = new javax.swing.GroupLayout(losowaniePanel);
losowaniePanel.setLayout(losowaniePanelLayout);
losowaniePanelLayout.setHorizontalGroup(
losowaniePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(losowaniePanelLayout.createSequentialGroup()
.addGap(162, 162, 162)
.addComponent(jLabel2)
.addContainerGap(160, Short.MAX_VALUE))
);
panelGlowny.add(losowaniePanel, "card2");
test.setText("test");
test.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
testActionPerformed(evt);
}
});
.....
private void testActionPerformed(java.awt.event.ActionEvent evt) {
losowanie_panel();
}
.....
public void losowanie_panel()
{
panelGlowny.removeAll();
panelGlowny.add(losowaniePanel);
invalidate();
repaint();
}