SWT

Share on:

Eclipse SWT cross platform (OSX/Linux/Windows) native controls for Go: https://github.com/timob/swt. Check the Readme, on how to get started.

This package is used by Cyan for its UI. Go's concurrency, synchronization and function closure features are useful in UI event/callback code. It is very suited to this kind of programming. UIs can be made very responsive, by easily running things in the background from an event handler.

Having a native Go UI option would be better, but this will take time.

Example

Demonstrates adding tab and tree controls to a window. (from examples dir)

package main

import (
	"github.com/timob/javabind"
	"github.com/timob/swt"
	"log"
	"os"
)

// Example as shown at https://www.eclipse.org/swt/

func main() {
	err := javabind.SetupJVM(os.Getenv("CLASSPATH"))
	if err != nil {
		log.Fatal(err)
	}

	var SWT *swt.SWT

	display := swt.NewWidgetsDisplay()
	shell := swt.NewWidgetsShell3(display)
	shell.SetLayout(swt.NewLayoutGridLayout2(2, true))

	tabFolder := swt.NewWidgetsTabFolder(shell, SWT.NONE())
	tabFolder.SetLayoutData(swt.NewLayoutGridData5(SWT.FILL(), SWT.FILL(), true, true, 2, 1))
	item := swt.NewWidgetsTabItem(tabFolder, SWT.NONE())
	item.SetText("Widget")

	composite := swt.NewWidgetsComposite(tabFolder, SWT.NONE())
	composite.SetLayout(swt.NewLayoutGridLayout())

	tree := swt.NewWidgetsTree(composite, SWT.BORDER())
	item.SetControl(composite)
	tree.SetHeaderVisible(true)
	tree.SetLayoutData(swt.NewLayoutGridData4(SWT.FILL(), SWT.FILL(), true, true))
	column1 := swt.NewWidgetsTreeColumn(tree, SWT.NONE())
	column1.SetText("Standard")
	column2 := swt.NewWidgetsTreeColumn(tree, SWT.NONE())
	column2.SetText("Widget")
	branch := swt.NewWidgetsTreeItem(tree, SWT.NONE())
	branch.SetText2([]string{"Efficient", "Portable"})
	leaf := swt.NewWidgetsTreeItem2(branch, SWT.NONE())
	leaf.SetText2([]string{"Cross", "Platform"})
	branch.SetExpanded(true)
	branch = swt.NewWidgetsTreeItem(tree, SWT.NONE())
	branch.SetText2([]string{"Native", "Controls"})
	leaf = swt.NewWidgetsTreeItem2(branch, SWT.NONE())
	leaf.SetText2([]string{"Cross", "Platform"})
	branch = swt.NewWidgetsTreeItem(tree, SWT.NONE())
	branch.SetText2([]string{"Cross", "Platform"})
	column1.Pack()
	column2.Pack()

	item = swt.NewWidgetsTabItem(tabFolder, SWT.NONE())
	item.SetText("Toolkit")

	button := swt.NewWidgetsButton(shell, SWT.CHECK())
	button.SetText("Totally")
	button.SetSelection(true)
	button.SetLayoutData(swt.NewLayoutGridData4(SWT.CENTER(), SWT.CENTER(), false, false))
	listener := NewSelectionListener(button)

	button = swt.NewWidgetsButton(shell, SWT.PUSH())
	button.SetText("Awesome")
	button.SetLayoutData(swt.NewLayoutGridData4(SWT.CENTER(), SWT.CENTER(), false, false))

	shell.Pack()
	shell.Open()

	for !shell.IsDisposed() {
		if !display.ReadAndDispatch() {
			display.Sleep()
		}
	}
}

Example apps:

AWS Plus: small utility to work with AWS

Windows 10