Clojure Swing Interop

These days, many apps default to use of a web interface for their user interfaces. Sometimes you just want a traditional graphic user interface (GUI) with your Clojure code without the hassle of creating a full blown web app. A lot can be said for double clicking an uberjar and seeing an appealing desktop app spring to life.

Those developing on vanilla Clojure running on the JVM have three main desktop options for GUI development: AWT, Swing, and JavaFX. AWT is considered to be an old tech with too many issues for standard development. JavaFX on the other hand is wonderful for huge projects managed by teams of dedicated developers, but a lot of work for little return when used on small projects. Swing still stands strong as the best choice for small projects that need a mature tool for GUI work.

Here are my collection of posts explaining Java Swing interop with Clojure.

Clojure Swing Tutorials and Posts

Quick Clojure GUI example using Swing

This is a barebones example for getting Swing up and going. It’s nice if you just want to get a “Hello World” with a GUI running.

 

Event Dispatch and Invoke Later

The first concept needed for successful Clojure Swing programming is an understanding of the event dispatch thread.

 

Clojure Swing JFrame Introduction

Clojure Swing JFrame example using JLabels and a BorderLayout.

 

Clojure JButton and ActionListener Example

Clojure Swing JButton using an ActionListener to print a simple message to the console.

 

Full Sample Clojure Swing Temperature Conversion App

Sometimes, you just need an actual code sample in a real app to see how to put together your own apps correctly. This Clojure Swing app demonstrated JLabel s, JTextField s, the event dispatch thread, ActionListener s, JFrame s and FlowLayout s.

 

Clojure Message Dialogs

Here’s how you integrate JOptionPane s into your Clojure program. You can have message dialogs, even if you don’t want a windowed application with a JFrame .

 

File Dialogs in Clojure

JFileChooser example to choose a file to slurp and print in Clojure.