Skip to content
daveray edited this page May 24, 2011 · 4 revisions

Event handler functions are single-argument functions that take an event object whose type depends on the event being fired, e.g. MouseEvent. For example, we can execute a function when a checkbox is checked:

(checkbox 
  :text "Check me" 
  :listen [:item-state-changed #(alert (selection! %))]))

Event handlers are installed with the (listen) function. Its first argument is a widget, or sequence of widgets, and then one or more event specs of the form event-name/function. For the most part, the name of the event is the name of a Swing event listener method. Here's an example that listens for some mouse events, assuming that p is bound to a widget:

(listen p
  :mouse-clicked (fn [e] ... do something ...)
  :mouse-entered (fn [e] ... do something ...)
  :mouse-exited  (fn [e] ... do something ...))

Note that these same arguments can be given to the :listen property when the widget is constructed.

(listen) returns a function which, when called, will remove all listeners installed by the (listen) call. There is no "remove-listener" function.

See seesaw.events/listen for more details.

Clone this wiki locally