I'm trying to to modify an existing class in a large application. The problem I am running into trying to convert an existing text box into a combo box when a user clicks on a button. The code right now uses a grid layout. I tried to just add the combo box in the method that creates the panel with .setVisible(false), thinking that when the listener for the button is selected I can set it to true. However, what happens is the formatting of the panel shifts everything over even if the combo box is invisible. The reason I am changing the text box into a combo box in the first place is that there is a certain scenario where the user needs to edit this panel and then processes the values when the button is selected. It is only in this panel that the button can be selected. Other parts of the application can insert data in the text box for display, hence the reason why I can not change the text box into a combo box.
I would appreciate any help or pointers anyone can give me on this. I've pretty much exhausted all resources here. Last resort is to just build the panel in the button listener method, which is really not an elegant solution.
I may be misinterpreting what you are trying to do, but perhaps a CardLayout will help you here. You can place both the combobox and the text box (what's a text box?) on a JPanel (if this is Swing) that uses a CardLayout. Then if you want to swap components you tell the CardLayout to change the component it shows. It's quite fun and easy to use. For more details, check out the Sun tutorials on this.