• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JInternalFrameを閉じる
#navi(../)
RIGHT:Posted by [[terai]] at 2008-05-05
*JInternalFrameを閉じる [#uf3146bf]
Posted by [[terai]] at 2008-05-05

#contents

**概要 [#ge2041fa]
JInternalFrameを閉じます。

-&jnlp;
-&jar;
-&zip;

#screenshot

**サンプルコード [#y0ad6085]
#code{{
closeSelectedFrameAction1 = new AbstractAction() {
  public void actionPerformed(ActionEvent e) {
    JInternalFrame f = desktop.getSelectedFrame();
    if(f!=null) {
      desktop.getDesktopManager().closeFrame(f);
    }
  }
};
}}
#code{{
closeSelectedFrameAction2 = new AbstractAction() {
  public void actionPerformed(ActionEvent e) {
    JInternalFrame f = desktop.getSelectedFrame();
    if(f!=null) {
      f.doDefaultCloseAction();
    }
  }
};
}}
#code{{
closeSelectedFrameAction3 = new AbstractAction() {
  public void actionPerformed(ActionEvent e) {
    try{
      JInternalFrame f = desktop.getSelectedFrame();
      if(f!=null) {
        f.setClosed(true);
      }
    }catch(java.beans.PropertyVetoException ex) {
      ex.printStackTrace();
    }
  }
};
}}
#code{{
disposeSelectedFrameAction = new AbstractAction() {
  public void actionPerformed(ActionEvent e) {
    JInternalFrame f = desktop.getSelectedFrame();
    if(f!=null) {
      f.dispose();
    }
  }
};
}}

**解説 [#v8ddc342]
上記のサンプルでは、選択されているJInternalFrameをツールバーのボタンやESCキー((OSがWindowsの場合のデフォルトは、Ctrl+F4))で閉じることができます。

- GREEN
-- DesktopManager#closeFrame メソッドを使用
- BLUE
-- JInternalFrame#doDefaultCloseAction メソッドを使用
//-- JInternalFrame#setDefaultCloseOperation の設定に従う
- YELLOW
-- JInternalFrame#setClosed(true) メソッドを使用
- RED
-- JInternalFrame#dispose メソッドを使用
-- 閉じた後、他のフレームに選択状態が移動しない

----
JDK 1.5 + WindowsL&F では、JInternalFrameを閉じたとき、アイコン化されているJInternalFrameには選択状態は移動しません。

//**参考リンク
**コメント [#o6a47604]
#comment