How to open warning dialog box in Java?

Posted on 2013-10-03
Medium Priority
Last Modified: 2013-10-07
I am working on a GUI and I need to bring a warning dialog box when a certain action happens.

In order to open this warning dialog box, I tried to use this code that I found on a web site but it did not work:

             // Customized MessageDialog with configured buttons
                MessageDialog dialog = new MessageDialog(shell, "My Title", null,
                    "My message", MessageDialog.ERROR, new String[] { "First",
                  "Second", "Third" }, 0);

Open in new window

The problem is MessageDialog cannot be resolved to a type and Eclipse does not recommend me to add any missing library.

What am I doing wrong in here? How can I open a warning dialog box?

This is the website that I used is:


Question by:Tolgar
  • 2
  • 2
LVL 36

Expert Comment

ID: 39544963
Do you need the specially customised buttons? Or are you just after a plain warning message type dialog box?

If you don't need the customised buttons, rather than using the JFace's MessageDialog, have you tried just using a standard SWT MessageBox as demonstrated in the first code example on the page that you linked too?

Author Comment

ID: 39545217
I don't need any fancy customized buttons but I would like to have a message on the dialog box and a ok button to close it.

So do you think I can still use swt message box?
LVL 36

Accepted Solution

mccarl earned 1600 total points
ID: 39545285
So do you think I can still use swt message box?
I can't see why not. As I said, the link that you posted gives a small example of creating/opening this, you would probably just want to change the icon style from ICON_QUESTION to ICON_WARNING if that is what you want (Refer to the javadoc that I linked to above, for all possible values)
LVL 37

Assisted Solution

zzynx earned 400 total points
ID: 39545533
Have a look at this article How to Make Dialogs
LVL 37

Expert Comment

ID: 39552454
Thanx 4 axxepting

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
AngularJS web development a very simple procedure. So, to put it, in short, AngularJS’ stand out features are – Two-way data binding, MVC structure, directives, templates, dependency injections and testing.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

624 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