关闭JFrame时如何在后台运行应用程序? [英] How to Run application in background when close the JFrame?

查看:161
本文介绍了关闭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
    • 设置当用户在此框架上启动关闭"时默认情况下将发生的操作.您必须指定以下选项之一:

      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".

      • 然后从 SystemTray 调用JFrame.setVisible(true),此事件可通过

        • then from SystemTray to call JFrame.setVisible(true), this event is accesible from

          1. TrayIcon

          JPopupMenu added to SystemTray

        • 这篇关于关闭JFrame时如何在后台运行应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆