Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

application preventing windows from shutting down

 
Carey Brown
Ranch Hand
Posts: 1378
16
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding a WindowListener to stop the Timer in its windowClosed event.
 
Carey Brown
Ranch Hand
Posts: 1378
16
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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.

 
Rob Camick
Ranch Hand
Posts: 2555
9
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 1378
16
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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.
 
Clo Knibbe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Randall Twede
Ranch Hand
Posts: 4369
3
Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic