How can I replace one JPanel with another JPanel in the same position?
I have a JFrame with about four frames. After a given action I want to replace one panel with another in the same position. My method for switching them looks like this (the this object is a class which extends JFrame ): public void switchPanel(){ mainPanel.remove(introPanel); mainPanel.add(questionPanel); this.repaint(); } The original creation of the window looks like this: mainPanel.add(titlePanel); mainPanel.add(sidePanel); mainPanel.add(introPanel); You ask: How can I replace one JPanel with another JPanel in the same position? Very easily: use a CardLayout as this tool was built for just