aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes application preventing windows from shutting down Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "application preventing windows from shutting down" Watch "application preventing windows from shutting down" New topic
Author

application preventing windows from shutting down

Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 207

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.


Sent from my IBM 360 mainframe
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Try adding a WindowListener to stop the Timer in its windowClosed event.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 207

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

Joined: Jun 13, 2009
Posts: 2215
    
    7
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

Joined: Nov 19, 2001
Posts: 207

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

Joined: Dec 02, 2011
Posts: 4
Hello Carey, did you ever solve this problem? I am having the same problem with this minimal program.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

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

Joined: Dec 02, 2011
Posts: 4
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

Joined: Oct 21, 2000
Posts: 4347
    
    2

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


SCJP
Visit my download page
Clo Knibbe
Greenhorn

Joined: Dec 02, 2011
Posts: 4
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

Joined: May 03, 2008
Posts: 4658
    
    5

Clo, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/awt-swing/52130-simple-swing-application-prevents-logoff-restart.html


luck, db
There are no new questions, but there may be new answers.
Clo Knibbe
Greenhorn

Joined: Dec 02, 2011
Posts: 4
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.
 
Don't get me started about those stupid light bulbs.
 
subject: application preventing windows from shutting down