I have two components in a JFrame that I want to switch between by using the getContentPane().setComponentZOrder. I have a button on each component where the onclick ActionEvent is to pull the other Component to the top, so when I'm viewing component1, I call getContentPane().setComponentZOrder(component2, 1) when I click the button. However, this doesn't bring component2 to the top, it actually doesn't do anything. I tried setting component0 to 0, and component2 to 1, but that doesn't work either. I also tried calling the repaint() method on the contentpane, and that doesn't do anything either.
Setting the zorder on the component should move the components back and forth right? Am I doing something wrong??
private void analyzeButtonAction(ActionEvent actionEvent)
Are you sure that you don't want to use a CardLayout here? This would allow you to easily swap components without fuss.
Works like a dream. Thanks!!