Java JFrame removeall挂起一个应用程序

时间:2012-08-20 17:13:16

标签: java swing concurrency jframe event-dispatch-thread

我有以下代码:

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
    }
};

我的应用程序依赖于EventDispatchThread.java中的以下代码:

void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) {
    addEventFilter(filter);
    while (doDispatch && cond.evaluate()) {
        if (isInterrupted() || !pumpOneEventForFilters(id)) {
            doDispatch = false;
        }
    }
    removeEventFilter(filter);
}

while循环是无限的,它会挂起我的应用程序。当.removeAll()不存在时,应用程序不会挂起,但我对旧控件进行了新的控制。我找到了一个解决方法,通过处理框架并再次创建它,但它看起来很讨厌。如果需要,将提供附加代码。请帮忙。

1 个答案:

答案 0 :(得分:0)

从评论中移出以获得更好的观点:

frameCrewSelection.getContentPane().removeAll(); frameCrewSelection.setContentPane(formCrewSelectionForm(SpaceObjectArray.findMan‌​nedByName(comboVehicle.getSelectedItem().toString())));

让它发挥作用。