2012-05-09 12 views
2

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

私のエスケープ機能は、上記のようである:

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のを持っているし、次に実行されていること停止する必要があります。

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

ありがとうございます。

+5

よりよいのために[KeyBindings](http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding)に関する問題を示した[SSCCE](http://sscce.org/)で質問をすぐに編集してください。 html)と[JProgressBar](http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html)を参照してください。 – mKorbel

答えて

1

私は理解して完全にわからないんだけど、あなたはJProgressBarのへのすべての参照を検索するに

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

} 

のようなものを使用することができ、そこからあなたがやりたいことができます...

関連する問題