2

JprogressBarを使用しているアプリケーションで作業しています。何かをしていると、プログレスバーが実行されます。そこにエスケープ機能も追加しました。誰かがキーボードのエスケープボタンをクリックすると、フォーカスされたJpanel / Jdialog/JFrameが破棄されます。正常に動作します。私の問題は、JprogressBarが停止していないことです。Jpanel / Jdialog / JFrameがエスケープボタンで閉じられている場合、その親がJProgressBarを持っている場合は、停止する必要があります。これどうやってするの?すべてのJpanel/Jdialog / JFrameの親は異なる可能性がありますか?

私のエスケープ機能は上記のとおりです:

public static void setDisposeOnEsc(JComponent c, final Object promptControl) {
        Action escape = new AbstractAction() {

            {
                putValue(NAME, "escape");
            }

            public void actionPerformed(ActionEvent e) {
                    JComponent source = (JComponent) e.getSource();
                    try {
                        Window window = SwingUtilities.getWindowAncestor(source);
                        window.dispose();
                    } catch (Exception ex) {
                    }
                    try {
                        Dialog dialog = (Dialog) source.getFocusCycleRootAncestor();
                        dialog.dispose();
                    } catch (Exception ex) {
                    }
                    try {
                        JFrame jFrame = (JFrame) source.getFocusCycleRootAncestor();
                        jFrame.dispose();
                    } catch (Exception ex) {
                    }   
            }
        };
        Object name = escape.getValue(Action.NAME);
c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"),name);
        c.getActionMap().put(name, escape);
    }

上記の方法で破棄されたJpanel/Jdialog / JFrameがあれば、それを実行したいと思います。その親がJprogressBarを持っていて実行されている場合は、停止する必要があります。

私の英語はあまり上手ではないので、文法の間違いは無視してください。

前もって感謝します。

4

1 に答える 1

1

私が理解しているかどうかは完全にはわかりませんが、次のようなものを使用できます

public static <T extends Component> List<T> findAllChildren(JComponent component, Class<T> clazz) {

    List<T> lstChildren = new ArrayList<T>(5);
    for (Component child : component.getComponents()) {

        if (clazz.isInstance(child)) {

            lstChildren.add((T) child);

        }

        if (child instanceof JComponent) {

            lstChildren.addAll(findAllChildren((JComponent)child, clazz));

        }

    }

    return Collections.unmodifiableList(lstChildren);

}

JProgressBar へのすべての参照を見つけるには、そこから必要なことを行うことができます...

于 2012-07-11T00:49:40.600 に答える