Clojure: Java GUI Problem
I have this little piece of code here.
(ns experiments
(:import (javax.swing JFrame JLabel)))
(defn crea开发者_JAVA百科te-frame [title text]
(doto (JFrame. title)
(.add (JLabel. text))
(.pack)
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
(.setVisible true)))
Now I run a REPL (Clojure Box, basically emacs + slime), starting it with the right classpath and so on, call (use 'experiments) - which works - and then call
(create-frame "Foo" "Bar")
.
Then... nothing. The REPL hangs up forever, no frame appears, nothing.
You should be talking to Swing from the event dispatch thread, for a start. Have a look at clojure.contrib.swing-utils/do-swing
.
Your code works for me using Sun's JDK 1.6.0_26 and Clojure 1.2.1 on Ubuntu 11.04... However the window frame is very small because it is packed around a small "Bar" label. Are you sure you didn't miss it, and the window is actually nestling somewhere on your desktop?
Also, as I recollect (I might be wrong here), but I thought there were Swing issues with the ubuntu-default IcedTea JRE - if you're using this, try the proper Sun/Oracle JRE instead.
精彩评论