0

I want a button to change the contentPane in a frame. An admin panel and a user panel in two different JPanel classes that gets called in a MainWindow class with a frame.

My code looks as follows:

The method the button calls:

public void ChangeContent() throws Exception{
    MainWindow mw = new MainWindow();
    AdminUI admin = new AdminUI ();
    mw.frame.getContentPane().removeAll();
    mw.frame.setContentPane(admin);
    mw.frame.revalidate();
    mw.frame.repaint();

}

This is the method being called in my "public MainWindow()" method in the MainWindow class (the one with the frame) to show the contentPane in the beginning:

public void Admin() throws Exception {
        frame = new JFrame("Admin Panel");
        frame.setResizable(false);
        frame.setBounds(100, 100, 256, 457);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        AdminUI Admin = new AdminUI();
        frame.setContentPane(Admin);
    }

An equal method exists for the userUI.

I have tried just called the userUI() method in the MainWindow when I press a button, but that doesn't refresh the window, and neither does the ChangeConten() method. I need some help. I used the search feature on Stackoverflow to no success.

4

0 回答 0