Posted by terai at 2008-05-05
JInternalFrameを閉じる
JInternalFrameを閉じます。
サンプルコード
closeSelectedFrameAction1 = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
JInternalFrame f = desktop.getSelectedFrame();
if(f!=null) {
desktop.getDesktopManager().closeFrame(f);
}
}
};
closeSelectedFrameAction2 = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
JInternalFrame f = desktop.getSelectedFrame();
if(f!=null) {
f.doDefaultCloseAction();
}
}
};
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();
}
}
};
disposeSelectedFrameAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
JInternalFrame f = desktop.getSelectedFrame();
if(f!=null) {
f.dispose();
}
}
};
解説
上記のサンプルでは、選択されているJInternalFrameをツールバーのボタンやESCキー*1で閉じることができます。
- RED
- JInternalFrame#dispose メソッドを使用
- 閉じた後、他のフレームに選択状態が移動しない
- GREEN
- DesktopManager#closeFrame メソッドを使用
- BLUE
- JInternalFrame#doDefaultCloseAction メソッドを使用
- YELLOW
- JInternalFrame#setClosed(true) メソッドを使用
JDK 1.5 + WindowsL&F では、JInternalFrameを閉じたとき、アイコン化されているJInternalFrameには選択状態は移動しません。