In the JFrame I have two components JMenuBar and JPanel. A selection in one of the options in menu bar change the content of panel as
JMenuItem jmiAddEmployee = new JMenuItem("Add Employee");
jmiAddEmployee.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
mainPanel.removeAll();
mainPanel.add(addEP);
validate();
}
});
This will replace the content, unfortunately if the previous components in the old one been longer then the new ones I will get new components with bits of old where the content is shorter. Is there any solution to this problem or do I need to swap my JMenuBar+JPanel for JTabbedPane?