public static void loadPanel(JPanel oldPanel, JPanel newPanel){ if(oldPanel == null){ frame.add(newPanel); }else{ frame.remove(oldPanel); frame.add(newPanel); frame.invalidate(); frame.revalidate(); frame.repaint(); frame.setVisible(false); frame.setVisible(true); } }
I'm using this code to try and switch the frame's panel. It works, but when I move the frame a echo of the old panel still exists. I was thinking and I thought that it may be more efficient to just use the same jpanel over and over again throughout the program. In order to easily point out errors within sections of the program, I kept each JPanel separated in its own class, which are all extended to the frame class. So I think I will try to use one JPanel and transition to sections by removing all components, add the new stuff, and refresh everything. Hopefully this idea will work tomorrow. If someone has found a better way or fix, please post.