• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Minimize to tray on close button click.

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have made a jframe in which i am using setDefaultCloseOperation(HIDE_ON_CLOSE) operation. By this when i click on close button of window, frame simply hide and my tray icon doesn't disappear but when i click on Jbutton named as CLOSE, tray icon disappear because i have written System.exit(0) in button action performed method. Now I want that when i click on CLOSE Jbutton, tray icon should not disappear from its position.

regards....
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of System.exit(0); use setVisible(false);
 
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or find the method which minimises the GUI. It may be called setIconified, or similar.
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's setExtendedState, with the state set to x | Frame.ICONIFIED where x is the current extended state. To restore, you then call setExtendendState with the state set to x & ~Frame.ICONIFIED with x again being the current extended state. By using this approach, the frame will go back to the previous state - maximized or not.

However, this will still show the application in the task bar. You will need to call setVisible(false) as well. The best way to handle this:
- minimize by clicking the icon in the frame's title bar: use a WindowListener that calls setVisible(false) in the windowIconified method.
- minimize from code: first use setExtendedState as I described above, then call setVisible(false).
- restoring from code: first call setVisible(true), then use setExtendedState as I described above.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:
- minimize by clicking the icon in the frame's title bar: use a WindowListener that calls setVisible(false) in the windowIconified method.
- minimize from code: first use setExtendedState as I described above, then call setVisible(false).



Haven't tested, but the WindowListener's windowIconified(...) should be called regardless of whether the window was iconified/minimized by user action or code execution. So the bolded part shouldn't be needed.
 
Rob Spoor
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're completely right. I missed that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic