What is the best way to do GUIs in Clojure? What is the best way to do GUIs in Clojure? java java

What is the best way to do GUIs in Clojure?


I will humbly suggest Seesaw.

Here's a REPL-based tutorial that assumes no Java or Swing knowledge.


Seesaw's a lot like what @tomjen suggests. Here's "Hello, World":

(use 'seesaw.core)(-> (frame :title "Hello"       :content "Hello, Seesaw"       :on-close :exit)  pack!  show!)

and here's @Abhijith and @dsm's example, translated pretty literally:

(ns seesaw-test.core  (:use seesaw.core))(defn handler  [event]  (alert event    (str "<html>Hello from <b>Clojure</b>. Button "      (.getActionCommand event) " clicked.")))(-> (frame :title "Hello Swing" :on-close :exit           :content (button :text "Click Me" :listen [:action handler]))  pack!  show!)


Stuart Sierra recently published a series of blog posts on GUI-development with clojure (and swing). Start off here: http://stuartsierra.com/2010/01/02/first-steps-with-clojure-swing


If you want to do GUI programming I'd point to Temperature Converter or the ants colony.

Many things in Swing are done by sub-classing, particularly if you are creating custom components. For that there are two essential functions/macros: proxy and gen-class.

Now I understand where you are going with the more Lispy way. I don't think there's anything like that yet. I would strongly advise against trying to build a grandiose GUI-building framework a-la CLIM, but to do something more Lispy: start writing your Swing application and abstract out your common patterns with macros. When doing that you may end up with a language to write your kind of GUIs, or maybe some very generic stuff that can be shared and grow.

One thing you lose when writing the GUIs in Clojure is the use of tools like Matisse. That can be a strong pointing to write some parts in Java (the GUI) and some parts in Clojure (the logic). Which actually makes sense as in the logic you'll be able to build a language for your kind of logic using macros and I think there's more to gain there than with the GUI. Obviously, it depends on your application.