java - 关闭 JFrame 时如何在后台运行应用程序?

标签 java swing jframe system-tray

我在我的 java 应用程序中使用了一个系统托盘。我想消失 GUI 并在后台 运行应用程序,但是当用户单击 JFrame 的关闭 按钮时系统托盘必须保持可用。

最佳答案

I want to disappear the GUI and run the application in background, but system tray must remain available when user click on close button of JFrame.

设置当用户在此框架上启动“关闭”时默认发生的操作。您必须指定以下选项之一:

DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object.

HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects.

DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects.

EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.

The value is set to HIDE_ON_CLOSE by default. Changes to the value of this property cause the firing of a property change event, with property name "defaultCloseOperation".

关于java - 关闭 JFrame 时如何在后台运行应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15441431/

相关文章:

java - 为什么 Windows LookAndFeel 使字体太小?

java - 为什么在编辑节点后,JTree 会短时间失去焦点?

java - 更改 JScrollPane 中的 JScrollBars 值时出现问题 : 90 is the magic number apparently

java - 无法在 JBoss AS 7 ("Can' 中获得持久性 t 找到名为 subdeployment 的部署单元”)

java - 为什么 getEntry(Object key) 没有暴露在 HashMap 上?

java - 如何用新的散点更新绘图区域?

java - 如何在 JButton 中添加图标

java - JFrame 和 JPanel

java - 检测 UPDATE 语句中哪些 SQL 列发生了更改

java - Struts 操作相关问题