I have a JFrame and in that I have many controls. I call this frame a number of times, and sometimes I have to hide some of controls. When I hide the controls, the position of other controls which are not hidden change automatically. I want to avoid this behaviour. Please help in this regard.
pnlRec.setVisible(true);
btnNew.setVisible(false);
I would suggest a solution based on
CardLayout. Place all the components to be hidden in aJPanelwithCardLayout. Each the panel should have 2 cards – the original component and empty panel. Instead of hiding the component just swap the cards showing the empty card panel.That should keep the layout the same.