Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An example boot-ified Swing app that contains a JavaFX WebView (Webkit instance).
#!/usr/bin/env boot
;; -*- mode: Clojure;-*-
(set-env! :dependencies '[[seesaw "1.4.5"]])
(use 'seesaw.core)
(import '(javafx.scene.web WebView)
'(javafx.scene SceneBuilder)
'(javafx.scene.layout VBoxBuilder))
;; need to wrap calls that happen in the UI thread
(defn run-later*
(javafx.application.Platform/runLater f))
(defmacro run-later
[& body]
`(boot.user/run-later* (fn [] ~@body)))
(defn run-now*
(let [result (promise)]
(deliver result (try (f) (catch Throwable e e))))
(defmacro run-now
[& body]
`(boot.user/run-now* (fn [] ~@body)))
;; a couple of helpers for the webview
(defonce web-view-panel (javafx.embed.swing.JFXPanel.))
(def web-view (atom nil))
(def engine (atom nil))
(defn set-html! [html]
(run-later (.loadContent @engine html)))
(defn -main [& args]
(native!) ;; native look & feel, please
;; set up the webview in a JavaFX "scene"
(reset! web-view (doto (WebView.) (.setPrefHeight 900)))
(reset! engine (.getEngine @web-view))
(.setScene web-view-panel
(.. SceneBuilder create
(height 980) (width 640)
(root (.. VBoxBuilder create
(minHeight 980) (minWidth 640)
(children [@web-view])
;; put the web-view in a Swing window frame
(-> (frame :title "Füchse"
:content web-view-panel
:on-close :exit)
;; deliver an important message
(set-html! "<html><body><strong style='font-size:36px;'>Füchse sind gar keine Rudeltiere</strong></body></html>")
;; when run in a boot script, the main thread exits and takes the UI
;; thread with it (?!?), so I added this as a gross hack to prevent
;; that
(println (let [p (promise)] @p)))

This comment has been minimized.

Copy link

kahunamoore commented Oct 19, 2015


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.