Skip to content

Instantly share code, notes, and snippets.

@lildata
Last active November 15, 2015 17:33
Show Gist options
  • Save lildata/9314976bfb79ce629806 to your computer and use it in GitHub Desktop.
Save lildata/9314976bfb79ce629806 to your computer and use it in GitHub Desktop.

Doc / links

some help from (seesaw.dev/show-options) & (seesaw.dev/show-events)

user=> (use 'seesaw.core)
nil
user=> (use 'seesaw.dev)
nil
user=> (show-options (label))
;... prints a long list of options along with example values ...
user=> (show-events (label))
;... prints a long list of supported events ...
(def button1 (button :text "Click Me"))
(defn alert1 [e] (alert e "I'm an alert"))
(defn alert2 [e] (alert e "I'm another alert"))
(listen button1 :action alert1)
(listen button1 :action alert2)
; bonus ;-)
(listen buttons1 :mouse-entered #(config! % :foreground :blue)
:mouse-exited #(config! % :foreground :red))
(defn display
[content]
(config! f :content content)
content)

Swing is single threaded nearly all UI operations should be executed on the Swing UI dispatch thread.

To facilitate this, Seesaw includes the invoke-now and invoke-later macros.

  • invoke-now executes forms on the UI thread and waits for their completion
  • invoke-later schedules the forms for execution sometime in the future

Long running tasks should be run on another thread (with future or whatever you like) and invoke-later should be used to trigger any UI updates resulting from that thread.

A typical use for invoke-later is to start an app:

(defn -main [& args]
  (invoke-later
    (show! (frame :title "Hello" :content (...)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment