关闭JFrame时如何在后台运行应用程序?
我在Java应用程序中使用了系统任务栏.我想消失GUI 并在后台中运行该应用程序,但是当用户单击JFrame的关闭按钮时,系统托盘必须保持可用. /p>
I used a system tray in my java application. 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.
我想消失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.
- 设置适当的 JFrames
DefaultCloseOperation
,JFrame.setDefaultCloseOperation(HIDE_ON_CLOSE)
的方法,默认情况下在API中实现 - set proper JFrames method for
DefaultCloseOperation
,JFrame.setDefaultCloseOperation(HIDE_ON_CLOSE)
, by default implemented in API -
然后从
SystemTray
调用JFrame.setVisible(true)
,此事件可通过-
then from
SystemTray
to callJFrame.setVisible(true)
, this event is accesible fromJPopupMenu added to SystemTray
-
设置当用户在此框架上启动关闭"时默认情况下将发生的操作.您必须指定以下选项之一:
Sets the operation that will happen by default when the user initiates a "close" on this frame. You must specify one of the following choices:
DO_NOTHING_ON_CLOSE(在WindowConstants中定义):什么也不要做;要求程序处理 注册的WindowListener对象的windowClosing方法.
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(在WindowConstants中定义):调用任何已注册的WindowListener对象后,自动隐藏框架.
HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects.
DISPOSE_ON_CLOSE(在WindowConstants中定义):调用任何已注册的WindowListener后自动隐藏和处置框架 对象.
DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects.
EXIT_ON_CLOSE(在JFrame中定义):使用系统退出方法退出应用程序.仅在应用程序中使用它.
EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.
默认情况下,该值设置为HIDE_ON_CLOSE.价值的变化 此属性导致触发属性更改事件,具有 属性名称"defaultCloseOperation".
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".