• 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

A question about closing a shell in SWT

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, everyone!
I am writing a desktop application using SWT, but I got a seemingly-trival problem, that's I don't know how to prevent unintentional closing the application window by clicking the close box of the window. I want to fulfill such goal: when a user click on the close box of the window, a message box with a ok button and a cancel button on it will pop up to warn the the user, if the user click the ok, the application window will be closed , otherwise the window will remain opening. thx a lot!
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

One solution is to use JFace's ApplicationWindow & override ApplicationWindow.close() method. This method is called when the user closes the window. You can then do something like:

public boolean close() {

String title = "Confirm";
String message = "Are you sure you want to close this window?";

if (org.eclipse.jface.dialogs.MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), title, message)) {
super.close();
}

Hope it helps!
 
Peng Fan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi: J Arshad,thank you for your suggestion.
But, what a pity, actually I am currently write a web-based warehouse management system and most of it have been completed. If I adopted your solution, most my system's structure would be altered. I don't know whether you or any other guy could figure out a better solution! Thanks again for all your generous help!
 
A feeble attempt to tell you about our stuff that makes us money
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic