Skip to content

Programming · Games · Life outdoors

Clojure GUI using Swing

(See my full list of Clojure Swing examples and tutorials at Clojure Swing Interop)

Simple Clojure Swing Example

Simple Clojure Swing Example

Here’s a really brief example for building a Java Swing app using Clojure.

(ns myswingproject.core
(:import
[javax.swing SwingUtilities JFrame JLabel]))
(defn create-and-show-gui
[]
(let [my-frame (doto (JFrame. "My Frame")
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE))
my-label (JLabel. "Hello UI")
content-pane (.getContentPane my-frame)]
(.add content-pane my-label)
(.pack my-frame)
(.setVisible my-frame true)))
(defn gui []
(SwingUtilities/invokeLater create-and-show-gui))
(gui)