Solved

How to quit a GUI application in SWT?

Posted on 2013-06-19
1
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 52
servlet example 11 56
eclipse apache tomcat admin console 52 149
Notify sent to other threads in Java 9 42
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

756 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