sam
sam

Reputation: 611

displaying a Message using SWT

I am trying to a display message when i will push save button saying that the content got saved using SWT. Can anyone please help me.

Note: I am not using Jface, Shell, Display. I am using a Composite.

Upvotes: 2

Views: 4188

Answers (2)

Shishir Pandey
Shishir Pandey

Reputation: 293

Alternatively you can use as below

MessageBox box = new MessageBox(comp.getShell(), SWT.CANCEL | SWT.OK);

Where comp is Composite.

Upvotes: 0

Georgian
Georgian

Reputation: 8960

Actually, you are using a Display and a base Shell. But these are hidden behind your Eclipse RCP app. I'm guessing you are creating your message dialog in the createContents(Composite) method of a ViewPart, correct?

You can access the Display with Display.getCurrent() anywhere in your code, and you can get the active Shell with parent.getActiveShell().

If you don't want to use JFace, use the MessageBox widget from SWT.

MessageBox box = new MessageBox(parent.getActiveShell(), SWT.CANCEL | SWT.OK);
box.setText("Title");
box.setMessage("This will be the message");

box.open(); // Call this on button pressed. Returns SWT.OK or SWT.CANCEL

If you want specific features for the MessageBox, you can either ask me in a comment, or check out these 18 Java code examples.

Upvotes: 6

Related Questions