Search code examples
javawindowsbackgroundjframewindow

How to keep a program running in background until user clicks its icon to make the window visible?


I am creating a java program that behaves like the Windows' start menu. I want it to run at startup and keep running in the background. When the user clicks application icon i want the window to become visible and again dissapear when the user is finished. The reason i want it to keep running in background is to make the window appear quickly as there are lots of images that need to be preloaded.


Solution

  • I assume that your java application is based on Swing/AWT.

    Step1: In Batch file/Shell script, please add & symbol at last and the java program will run it in background.

    Example: Content of batch file / shell script

    java XYZ &
    

    Step2: Please ensure that the your application has toplevel container which consists of

    • Sub container which has Icon (which is visible always)

    • Sub container like Jpanel/JFrame are initially drawn/painted with 'hide' option.

    It ensures that your application is not visible to normal user, but icon container is visible

    Step3: Based on user action on icon cotainer, you will hide/show the sub container of JPanel/JFrame.

    Step3: Please ensure that icon of your application