Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » System Tray menu "Exit" feature closing a dialog box
System Tray menu "Exit" feature closing a dialog box [message #460923] Sat, 10 September 2005 20:13 Go to next message
Zachary Calvert is currently offline Zachary CalvertFriend
Messages: 19
Registered: July 2009
Junior Member
I create a System tray menu and add an exit item as follows:

MenuItem exit = new MenuItem(menu, SWT.PUSH);
exit.setText("Exit");
exit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
parent.getDisplay().dispose();
}
});
This works perfectly if the application window is not opened. I can open it and close the application window, but using the exit button while the application window is shown creates a
Exception in thread "main" org.eclipse.swt.SWTException: Widget is disposed

I believe it is due to something in the main loop which contains

while (!display.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
I have not figured out how to stop the readAndDispatch() from generating the exception.

Any suggestions?

Thanks,
Zach
Re: System Tray menu "Exit" feature closing a dialog box [message #460936 is a reply to message #460923] Mon, 12 September 2005 12:44 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
dispose() says 'I have finished with this widget, and no-one else is going to use it' rather than 'close this window'. In particular, you're not expected to dispose() live windows, which if it is showing, it will be.

You probably want to use 'close()' instead.
Re: System Tray menu "Exit" feature closing a dialog box [message #460937 is a reply to message #460936] Mon, 12 September 2005 13:41 Go to previous messageGo to next message
Zachary Calvert is currently offline Zachary CalvertFriend
Messages: 19
Registered: July 2009
Junior Member
The problem is, I am done with the widget. I want it to close, dispose, and stop all processing without throwing exceptions. Calling close on the application window does not stop the entire program, and surprisingly enough it still throws an exception.

It is throwing the exception because on one thread it is processing the readAndDispatch, and on another thread managing the systemTray menu's selection listener it is attempting to close the app.
Re: System Tray menu "Exit" feature closing a dialog box [message #460942 is a reply to message #460937] Mon, 12 September 2005 15:07 Go to previous message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
Quite possibly, yes, this is due to a race condition between the threads.

What you might want to do is have some kind of boolean flag to determine if it is closing or not, and then if so ignore any exceptions in the processing loop. That tends to be the case for this sort of situation.
Previous Topic:Tooltip for a table column
Next Topic:BSF4REXX and SWT
Goto Forum:
  


Current Time: Thu Apr 25 19:54:20 GMT 2024

Powered by FUDForum. Page generated in 0.03077 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top