英文:
Switching between panels LayeredPane
问题
我正试图使用分层窗格在面板之间进行切换。
我已经添加了2个面板,它们正常工作(切换),
但是当我创建一个自己的类 public class AuthorPanel extends javax.swing.JPanel
并尝试将其添加到分层窗格时,无法正常工作。
我正在使用的方法:
public void switchPanels(JPanel panel){
jLayeredPane1.removeAll();
jLayeredPane1.add(panel);
jLayeredPane1.repaint();
jLayeredPane1.revalidate();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
switchPanels(jPanel3);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
switchPanels(jPanel2);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
AuthorPanel a = new AuthorPanel();
switchPanels(a);
a.setVisible(true);
}
英文:
i am trying to switch between panels using layered pane.
I have added 2 panels and they are working fine(switching),
but when i am creating the an own class public class AuthorPanel extends javax.swing.JPanel
and trying to add it on the layeredPane is not working
Methods i am using
public void switchPanels(JPanel panel){
jLayeredPane1.removeAll();
jLayeredPane1.add(panel);
jLayeredPane1.repaint();;
jLayeredPane1.revalidate();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
switchPanels(jPanel3);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
switchPanels(jPanel2);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
AuthorPanel a = new AuthorPanel();
switchPanels(a);
a.setVisible(true);
}
专注分享java语言的经验与见解,让所有开发者获益!
评论