User Tools

Site Tools


Dave Orme muses about agile and functional programming.

My current work emphasizes SOA applications using Scala, Kubernetes, and AWS with a React-based SPA front-end. I'm also interested in progressive web applications and developer tools.


Scala, Clojure, and FP


The Cloud

Data-First Development

Older work

Coconut Palm Software home

Donate Bitcoin:



Kubernetes, Docker, Streaming Data, Spark, Scala, Clojure, OSGi, Karaf, GCP, AWS, SQL


Everything I say here is my own opinion and not necessarily that of my employer.


Needed More Readable SWT Snippets

When creating small examples to illustrate a single SWT programming technique, the SWT team has been utilizing what they call snippets, or minimal SWT applications. These are great if you need to see at a glance everything related to the particular application in question.

However, suppose you are trying to illustrate a technique for working with, for example, the Label widget. In this case, all the housekeeping chores of creating the SWT Display, running the SWT event loop, and disposing of everything afterward just get in the way of communicating the technique you are trying to illustrate.

In other words, in order to illustrate SWT label usage, you'd really like to write something like the following:

public class Hello extends Snippet {
    public void setupUI(Shell parent) {
        parent.setLayout(new FillLayout());
        new Label(parent, SWT.NULL).setText("Hello, world");
    public static void main(String[] args) {
        new Hello();

I realized I had an itch; I just had to scratch it. Here's the result:

public class Snippet {
    public Snippet() {
        Display display = new Display();
        shell = new Shell(display);
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
    private Shell shell;
    // Returns the application shell
    protected Shell getShell() {
        return shell;
    // Override this method to set up your UI
    public void setupUI(Shell parent) {
    // Override this method to do something after the Shell closes
    // (print results, debug info, etc.).
    public void afterClose() {
    // Override this method to set a new default Shell size
    protected Point getDefaultSize() {
        return new Point(800, 600);

Feel free to use this code however you like, subject to the license terms at the bottom of this page.


blog/needed_more_readable_swt_snippets.txt · Last modified: 2014/10/17 22:08 (external edit)