简体   繁体   English

如何在Java Swing中使用[Esc]键最小化JInternalFrame?

[英]How to minimize JInternalFrame using [Esc] key in Java Swing?

I used InputMap and ActionMap to binding Esc to closing window, by using setVisible(false) . 我使用InputMapActionMap通过使用setVisible(false)将Esc绑定到关闭窗口。 How can I create [Esc] Hotkey to minimize the window in java swing? 如何创建[Esc]热键以最小化Java swing中的窗口?

Instead of using 而不是使用

frame.setVisible( false );

You would use: 您将使用:

frame.setExtendedState(JFrame.ICONIFIED);

You should also check out Dialog Escape Key for a more complete implementation that will handle the Escape key. 您还应该签出Dialog Escape Key以获得更完整的实现,该实现将处理Escape键。 For example the code will allow closing of popup windows (on a combo box) to close before attempting to close the dialog. 例如,该代码将允许关闭弹出窗口(在组合框上)的关闭,然后再尝试关闭对话框。 The code was written for a dialog and would need to be modified slightly for a JFrame. 该代码是为对话框编写的,对于JFrame需要稍作修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM