I want to be able to set the content area of a JFrame after clicking a button inside one of these JPanels.
My architecture consists of a controller that creates a JFrame and the first JPanel inside it. Starting with the first JPanel, I call the method: setcontentpane (JPanel jpanel) on the controller. However, instead of loading the transferred JPanel, it does nothing but delete all panels (see code below)
ActionListener inside the first JPanel:
public void actionPerformed(ActionEvent arg0) { controller.setpanel(new CustomPanel(string1, string2)); }
Controller:
JFrame frame; public void setpanel(JPanel panel) { frame.getContentPane().removeAll(); frame.getContentPane().add(panel); frame.repaint(); } public Controller(JFrame frame) { this.frame=frame; }
Can someone tell me what I am doing wrong? Thanks:)
Julian
source share