Solved

How to quit a GUI application in SWT?

Posted on 2013-06-19
1
348 Views
Last Modified: 2013-06-21
Hi,
I am working on a GUI application and I use SWT.

I wonder how I can quit this application by clicking a button in the toolbar just like closing it by pressing the x sign on the corner of the window.

This is the code that creates the quit icon :

       
CustomToolbar custToolBar33333 = new CustomToolbar(compTB3, SWT.FLAT, "Next Actions");      
    
        item33333333 = new ToolItem(custToolBar33333.getToolBar(), SWT.PUSH);
        item33333333.setImage(image_exit); item33333333.setText("Quit"); item33333333.setToolTipText("Quit the tool");
        item3333333.addListener(SWT.Selection, toolBarListener);

Open in new window

0
Comment
Question by:Tolgar
1 Comment
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
ID: 39264353
in listener class add this code for this item:

try {
  if (!shell.isDisposed()) {
    shell.close();
    shell.dispose();
  }
} finally {
  display.dispose();
}

also you have to change "setShell" method in this way:

public void setShell(Shell shell, Display display) {
  this.shell = shell; this.display = display;
}

and to add reference to Display as a member of this class.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question