(ns swttestOn Mac, you will need to add the "-XstartOnFirstThread" command line option or your application will crash soon after launching.
(:import (org.eclipse.swt.widgets Display Shell)
(org.eclipse.swt.layout GridLayout)
(org.eclipse.swt.events ShellAdapter)))
(defn create-shell [display shell]
(let [layout (GridLayout.)]
(doto shell
(.setText "SWT Test")
(.setLayout layout)
(.addShellListener
(proxy [ShellAdapter] []
(shellClosed [evt]
(System/exit 0)))))))
(defn swt-loop [display shell]
(loop []
(if (.isDisposed shell)
(.dispose display)
(do
(if (not (.readAndDispatch display))
(.sleep display))
(recur)))))
(defn begin []
(let [display (Display.)
shell (Shell. display)]
(create-shell display shell)
(.setSize shell 700 700)
(.open shell)
(swt-loop display shell)))
(begin)
Update:
I originally left out the line "(create-shell display shell)". The code above is now corrected.
See also:
6 comments:
I cant get this to work:
java -XstartOnFirstThread -cp .:swt-3.4-carbon-macosx/swt.jar -jar /opt/local/bin/clojure/clojure.jar swttest.clj
it says java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Display (swttest.clj:0)
Where exactly is the create-shell function supposed to be used?
Where exactly is create-shell function supposed to be used?
Don't you need to call create-shell at one point?
Janis and Vincent:
Thanks for catching my mistake. The code as it is above should work as intended now.
--Kevin
Mr. "Default",
Try this:
java -XstartOnFirstThread -cp .:path/to/clojure.jar:path/to/swt.jar clojure.lang.Script swttest.clj
--Kevin
Post a Comment