So I am writing a little app that needs to have one JPanel be added to the same area as another and have one show up when it's needed - AKA when a button is pressed, one disappears and the other shows up. As soon as I have time, I will clean up the post, but for now I kinda need to rush so I don't miss the bus home.
Also, if this is not possible, please tell me a way I can replicate the effect. Preferably within the same window.
SSCCE ex. imports:
public class Demo implements ActionListener {
static JButton switch = new JButton("Switch");
public static void main(String[] args) {
JFrame disp = new JFrame("Demo");
disp.setLayout(new BorderLayout());
disp.add(switch, BorderLayout.NORTH);
JPanel pan1 = new JPanel();
pan1.setBackground(Color.RED);
disp.add(pan1);
JPanel pan2 = new JPanel();
pan2.setBackground(Color.GREEN);
disp.add(pan2);
disp.setVisible(true);
}
void actionPerformed(ActionEvent e) {
System.out.println(e.paramString());
//Something to switch the JPanels when "switch" is pressed
}
}