0

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);
    }                        
  • 2
    1) *"switch between panels"* Use a [`CardLayout`](http://download.oracle.com/javase/8/docs/api/java/awt/CardLayout.html) as shown in [this answer](http://stackoverflow.com/a/5786005/418556). 2) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Apr 05 '20 at 18:34
  • 2
    Exactly-- sounds like you're trying to re-invent the CardLayout wheel. – Hovercraft Full Of Eels Apr 05 '20 at 18:34

0 Answers0