Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

application preventing windows from shutting down

 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a trivial swing application that is preventing windows from shutting down on Windows 7.

I have a JFrame initialized with:

I'm running the app from a shortcut that is invoking javaw.exe
I thought that this should do the trick but no luck. Any ideas?
Is there a shortcut property that I should be setting?
P.S. It does have one swing Timer in the app.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try adding a WindowListener to stop the Timer in its windowClosed event.
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I couldn't get your suggestion to work. Here's the complete source code. About as simple as you can get.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if( e.getButton() == 3 ) // right click



Instead you should be using:



Also, don't call your class Canvas. There is an AWT class with that name.

Your code worked fine for me. I did rename Canvas to Canvas2, although that should not any difference.

I'm using JDK6_7 on XP.
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Additional info: It appears that the act of having windows shutdown the application is somehow causing an infinite loop. I've tried some new things like DISPOSE_ON_CLOSE and also sending a CLOSING event instead of calling dispose() directly. Same result. If I Cancel the shutdown when windows fails to close the application the performance meter shows that one of the CPU's cores is slammed. I have to find and kill the javaw process to get it to stop.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Carey, did you ever solve this problem? I am having the same problem with this minimal program.

 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When Windows logs off it sends a close signal to all open windows. In your example your frame (window) is ignoring that request. If you change your default close operation to DISPOSE_ON_CLOSE or EXIT_ON_CLOSE it should end the JVM properly. If not then it is indeed a bug.
The reason it works with java is that there is an additional command prompt window. This is then closed, which causes it to end the JVM process it started.
 
Clo Knibbe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response Rob. As the comment in my code indicates, the setting for defaultCloseOperation appears to have no bearing on the problem. I have tried all possible values, including the default (which I believe is HIDE_ON_CLOSE, but I could be wrong). The behavior is the same in all cases: i.e. program isn't terminated on shutdown/logoff.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it certainly sounds like a bug to me. as you say it works fine it works fine when started with java.exe, that is the only way i have ever done it, i have no knowledge of javaw.exe
 
Clo Knibbe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Randall, if a (Windows) user double clicks on a .jar file, 'javaw.exe" is invoked, so that is how my users run my .jar file. I sometimes use the Command Prompt, where I can invoke either java.exe or javaw.exe.
 
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
Clo, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/awt-swing/52130-simple-swing-application-prevents-logoff-restart.html
 
Clo Knibbe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, db. I didn't consider this to be a cross post, since on this forum I was just asking the OP if he/she had resolved the problem.
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic