Java JFrame removeall hangs an application

只谈情不闲聊 提交于 2019-12-11 10:28:26

问题


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.findMan‌​nedByName(comboVehicle.getSelectedItem().toString())));

made it work.



来源:https://stackoverflow.com/questions/12042039/java-jframe-removeall-hangs-an-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!