The question is published on by Tutorial Guruji team.
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.
Answer
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.
- 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 (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”.
-
then from
SystemTray
to callJFrame.setVisible(true)
, this event is accesible from