javaswingjframejpanelwindowbuilder

How to instance a JPanel into panel in Jframe


Sorry if I might mix terms up. So I have a basic application where I would press the button and Jpanel1 with a label in it, would then switch/replace to JPanel2 that'll have a picture in it, all within the panel. enter image description here

The JPanel inside the box would change from Jpanel1 to JPanel 2 after pressing the button. So is their a way to instance a JPanel in a panel or JFrame? I can't find the method on how to fill the panel with the JPanel.


Solution

  • I ended using layeredPane with a card layout. Then I placed a panel using the center Border Layout, then instanced the JPanel as the panel from a different class.

    Picture of Windowbuilder layout

        panelPPBrowser = new JPanel();
        layeredPane.add(panelPPBrowser, "name_216881785358769");
        panelPPBrowser.setLayout(new BorderLayout(0, 0));
        
        panelBrowser panelBrowserCon = new panelBrowser();
        panelPPBrowser.add(panelBrowserCon, BorderLayout.CENTER);