How to Run application in background when close the JFrame? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to Run application in background when close the JFrame? without wasting too much if your time.

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.

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

We are here to answer your question about How to Run application in background when close the JFrame? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji