I have a class that extends JFrame and has a BorderLayout. It has two private instance variables of type JPanel. They are button panels and are called flipButton and trustButtons. When you click on a button, the button bar is replaced with another button bar. That is, if you click the button in flipButton, flipButton will be replaced with trustButtons. I tried to do it like this:
private class FlipListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
remove (flipButton);
add (confidenceButtons, BorderLayout.SOUTH);
validate ();
...
}
}
private class ColorListener implements ActionListener {
...
public void actionPerformed (ActionEvent e) {
...
remove (confidenceButtons);
add (flipButton, BorderLayout.SOUTH);
validate ();
}
}
Buttons in flipButton have FlipListeners, and those in which they are sure. Buttons have ColorListeners. When the program starts, clicking on the button will remove the panel, but nothing will be added to replace it. What am I doing wrong?
EDIT
CardLayout turned out to be a simple and easy solution. It turns out that the above code really works; The problem was a typo in another section of my code. > & L .; However, I have always had problems using these methods, and CardLayout, I believe, simplifies it for me. Thank you
Shelley
source share