 
 (defn show-in-frame
   "Creates new frame with thing embedded and shows it."
-  [^java.awt.Component thing]
-  (let [frame (JFrame.)]
-    (.add frame thing)
-    (.setVisible frame true)
-    (.setSize frame (Dimension. 500 200))
-    (.setDefaultCloseOperation frame JFrame/DISPOSE_ON_CLOSE)
-    frame))
+  [thing]
+  (-> (frame :content thing
+             :size [500 :by 200]
+             :on-close :dispose)
+      pack!
+      show!))
 
 (defn message-box
   "Pops up a swing message box."

  displayed in a message dialog."
  [frame title & body]
  `(try
    ~@body
    (catch Exception e#
      (javax.swing.JOptionPane/showMessageDialog ~frame
                                                 (apply str (get-root-cause e#) "\n"
                                                        (interpose "\n" (.getStackTrace e#)))
                                                 ~title
                                                 javax.swing.JOptionPane/ERROR_MESSAGE))))

(defn- add-handler
  "Adds an ActionListener to abstract-button that calls function with frame when
  activated (i.e. when actionPerformed is called)."
  [^javax.swing.AbstractButton thing frame function]
  (.addActionListener thing
    (proxy [ActionListener] []
      (actionPerformed [evt]
        (with-swing-error-msg frame "Error"
          (function frame))))))

(defn get-component
  "Returns the first component in component satisfing predicate."

  [^JFrame frame, icons]
  (let [our-icons (map #(make-icon frame %) icons)]
    (do-swing
     (let [toolbar (select frame [:JToolBar]),
           new-icons (collapse-separators (concat (.getComponents toolbar)
                                                  our-icons))]
       (.removeAll toolbar)
