JInternalFrameを閉じる
Total: 10029, Today: 1, Yesterday: 0
Posted by aterai at
Last-modified:
Summary
選択中のJInternalFrameをDesktopManagerなどを使用して外部から閉じる(JDesktopPaneから除去する)方法をテストします。
Screenshot

Advertisement
Source Code Examples
closeSelectedFrameAction1 = new AbstractAction() {
@Override public void actionPerformed(ActionEvent e) {
JInternalFrame f = desktop.getSelectedFrame();
if (f != null) {
desktop.getDesktopManager().closeFrame(f);
}
}
};
closeSelectedFrameAction2 = new AbstractAction() {
@Override public void actionPerformed(ActionEvent e) {
JInternalFrame f = desktop.getSelectedFrame();
if (f != null) {
f.doDefaultCloseAction();
}
}
};
closeSelectedFrameAction3 = new AbstractAction() {
@Override public void actionPerformed(ActionEvent e) {
try {
JInternalFrame f = desktop.getSelectedFrame();
if (f != null) {
f.setClosed(true);
}
} catch (PropertyVetoException ex) {
ex.printStackTrace();
}
}
};
disposeSelectedFrameAction = new AbstractAction() {
@Override public void actionPerformed(ActionEvent e) {
JInternalFrame f = desktop.getSelectedFrame();
if (f != null) {
f.dispose();
}
}
};
View in GitHub: Java, KotlinDescription
上記のサンプルでは、選択されているJInternalFrameをツールバーのボタンやEscキー(OSがWindowsの場合のデフォルトはCtrl+F4)で閉じることができます。
REDJInternalFrame#dispose()メソッドを使用- 閉じた後、他のフレームに選択状態が移動しない
GREENDesktopManager#closeFrame(JInternalFrame)メソッドを使用
BLUEJInternalFrame#doDefaultCloseAction()メソッドを使用
YELLOWJInternalFrame#setClosed(true)メソッドを使用
JDK 1.5+WindowsLookAndFeelではJInternalFrameを閉じたときアイコン化されているJInternalFrameには選択状態は移動しない
Reference
- <Swing Dev> 8 Review request for 8012004: JINTERNALFRAME NOT BEING FINALIZED AFTER CLOSING
- JDK-4759312 JInternalFrame Not Being Finalized After Closing - Java Bug System