Advertisement
mitrakov

SWT simple example

Feb 18th, 2019
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import org.eclipse.swt.SWT;
  2. import org.eclipse.swt.events.*;
  3. import org.eclipse.swt.widgets.*;
  4.  
  5. public class App {
  6.     public static void main(String[] args) {
  7.         final Display display = new Display(); // for MacOS X add "-XstartOnFirstThread" to VM arguments
  8.         final Shell shell = new Shell(display, SWT.SHELL_TRIM);
  9.         final Label label = new Label(shell, SWT.NONE);
  10.         label.setText("Hello world! Please click me!");
  11.         label.addMouseListener(new MouseAdapter() {
  12.             @Override
  13.             public void mouseDown(MouseEvent e) {
  14.                 final MessageBox messageBox = new MessageBox(shell);
  15.                 messageBox.setMessage("Message");
  16.                 messageBox.setText("Header");
  17.                 messageBox.open();
  18.             }
  19.         });
  20.  
  21.         label.pack();
  22.         shell.pack();
  23.         shell.open();
  24.  
  25.         while (!shell.isDisposed())
  26.             if (!display.readAndDispatch())
  27.                 display.sleep();
  28.         display.dispose();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement