在面板之间切换 LayeredPane

huangapple 未分类评论51阅读模式
英文:

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);
    }                        

huangapple
  • 本文由 发表于 2020年4月6日 02:32:31
  • 转载请务必保留本文链接:https://java.coder-hub.com/61047532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定