问题
I have the following code:
ActionListener listenerComboVehicle = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
comboVehicle.removeActionListener(listenerComboVehicle);
frameCrewSelection.removeAll();
frameCrewSelection.add(formCrewSelectionForm(SpaceObjectArray.findMannedByName(comboVehicle.getSelectedItem().toString()))); //Create some controls (Jcombobox comboVehicle included) and assign listeners to them.
formComboCrews(); //Modify JCombobox controls content
}
};
And my application hangs on the following code in EventDispatchThread.java:
void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) {
addEventFilter(filter);
while (doDispatch && cond.evaluate()) {
if (isInterrupted() || !pumpOneEventForFilters(id)) {
doDispatch = false;
}
}
removeEventFilter(filter);
}
The while loop is infinite and it hangs my application. When .removeAll() is absent, the application doesn't hang but I get new controls over old controls. I've found a workaround by disposing a frame and creating it again but it looks nasty. Additional code will be provided if needed. Please help.
回答1:
Moved from comments for better view:
frameCrewSelection.getContentPane().removeAll(); frameCrewSelection.setContentPane(formCrewSelectionForm(SpaceObjectArray.findMannedByName(comboVehicle.getSelectedItem().toString())));
made it work.
来源:https://stackoverflow.com/questions/12042039/java-jframe-removeall-hangs-an-application