Solved

How to quit a GUI application in SWT?

Posted on 2013-06-19
1
345 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now