I'm currently making a java swing GUI with the Netbeans GUI builder. I have a bunch of panels that are being replaced on my main JFrame as the user navigates the GUI and a controller class is taking care of this. At one step, however, there is a panel (FilterDefinitionPanel) that contains a combo box as well as a blank inner panel (QueryHelperPanel).
What I'd like to do is to swap out this inner panel with another I've created (StringQueryDefinitionPanel) depending on what the user selects in the combo box. So right now under my combo box's ComboBoxItemStateChanged event handler I have my controller class run this method:
public void selectFilterAttribute(Object item) {
/**
* Determine panel to create based on item selection. Currently always returns the same
* StringQueryDefinitionPanel.
*/
JPanel panel = this.getRequiredQueryHelperPanel(item);
/**
* Swap the placeholder QueryHelperPanel with the required one.
*/
((FilterDefinitionPanel) this.mainFrame.getMainPanel()).setQueryHelperPanel(panel);
/**
* Not sure if all of these are needed :\
*/
mainFrame.validate();
mainFrame.repaint();
mainFrame.pack();
}
This is what's happening in the FilterDefinitionPanel's setQueryHelper method:
public void setQueryHelperPanel(JPanel panel){
this.remove(queryHelperPanel);
this.queryHelperPanel=panel;
this.queryHelperPanel.repaint();
/**
* Again, not sure which refresh methods are needed...
*/
this.validate();
this.repaint();
}
Currently I think this is replacing my inner placeholder panel with ...something... , but the replacement seems to contain nothing. I don't know if it matters but both the placeholder and the replacement panel are the same size. I'm kind of a swing nub so any tips would be really appreciated.