Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:31:08+00:00 2026-06-11T10:31:08+00:00

I have a Java SWT application and i’m using this snippet of code to

  • 0

I have a Java SWT application and i’m using this snippet of code to display a message box.

    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            try {

                MessageBox objError = new MessageBox(SysTray.shell, SWT.ICON_ERROR);
                objError.setMessage(strMessage);
                objError.open();
                SysTray.shell.getDisplay().dispose();
                System.exit(1);

            } catch (Exception e) {
                e.printStackTrace(); // Nothing to be handled here.
            }

        }

    });

This piece of code doesn’t get executed when my SWT UI isn’t created and therefore this block does not run. This has happened in situations where my UI thread has crashed.

How can I check if my UI is already created and if it isn’t, I’d like to still show the message box to the user.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:31:09+00:00Added an answer on June 11, 2026 at 10:31 am

    The first parameter of MessageBox is the surrounding shell.

    You have to define a Display, and a Shell within the Display, to show the Message Box.

    Display display = new Display();
    Shell shell = new Shell(display);
    // Define message box
    shell.open();
    while (!shell.isDisposed()) {
        if (display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
    

    Edited to add and answer the comment:

    To determine if a Display and Shell exist –

        Display display = Display.getCurrent();
        if (display != null) {
            Shell[] shells = display.getShells();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm designing a Java application using SWT. I have some tables which will display
I have a Java Application using SWT as the toolkit, and I'm getting tired
I have written a Java GUI using SWT. I package the application using an
I already have Java code to display and process data from a database. I
I have inherited development of a Java/SWT application running on Windows only. One of
I have written an SWT Java application and would like to configure it to
On my cross-platform SWT Java application, I'm using TrayItem's setImages() function to set the
I am trying to communicate with Excel from a Java/SWT application. I have been
I'm creating an application with Java and SWT, and have a workspace generated on
I am writing a Java application using SWT widgets. I would like to update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.