I'm developing a JFrame that will add some components dynamically. When i add a new component, i want all components that are below, to be shifted down, and when i remove it, i want everything to return as it was.
Is there a specific LayoutManager to use in order to fulfill my requirements ?
This is just a suggestion it might work and might not . . .
Try GridBagConstraints:- Are you familiar with Cay Horstmann's GBC class? It extends GridBagConstraints and makes GridBagLayout easier to use. Go through it until you understand it. There is a description of the GBC class in Horstmann's book pages 430-434 (C Horstmann, G Cornell, Core Java 2-vol I Fundamentals 7/e, Santa Clara: Sun Microsystems Press (Prentice-Hall) (2004)).
Try putting all your Components into a List; add to and remove from the position 0 in the List. Whenever you add a Component, remove everything, then replace everything by going through the List; use the index value to set the gridy value of the Constraints, then call validate(). Whenever you remove a Component, you will have to remove it from the List and the JFrame, then again go through the indices to set up the gridy value.
Alternative suggestion:- You may be able to use a GridLayout with one column instead and always add or remove at index 0. [ March 28, 2007: Message edited by: Campbell Ritchie ]