Java - SWT - Hello World tutorial

Hello World!
It seems to me that I already seen this expression somewhere.

Well, let's go?

First thing to know is that we need two SWT widgets to make a window appear:

  • Display
  • Shell

Then a loop while to tell the program to continue displaying the window until someone close it.
Now, the code.

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Helloworld {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setSize(300, 300);
        shell.setText("Hello World");;
            if (!display.readAndDispatch())

Right click on the HelloWorld class and run it as a Java Application.
The window is coming and displays the title Hello World.

Really easy, isn't it? surprise

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.