I have a program where I have a JFrame
with a JButton
in it. When the user clicks the JButton
, all Components
of the JFrame
are removed, and a JPanel
with red background is added to it.
When I click the JButton
, that red JPanel
does not become visible unless I resize the JFrame
(I am using Windows 7). Is there a way to achieve what I want without having to manually resize the JFrame
?
Here is a part of the code I am using:
public class Demo implements ActionListener{
public static void main(String args[]){
...............
button.addActionListener(this); //'button' is an object of Jbutton class.
frame.setVisible(true); //'frame' is an object of JFrame class.
............
}
public void actionPerformed(ActionEvent ae){
frame.removeAllComponents();
frame.add(panel1); //panel1 is an object of Jpanel class with red background.
/* Here is where my problem lies.
panel1 is not visible to me unless I manually resize the JFrame. */
}
}