Skip to content

Instantly share code, notes, and snippets.

@raek
Created March 10, 2011 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/864942 to your computer and use it in GitHub Desktop.
Save raek/864942 to your computer and use it in GitHub Desktop.
(defn prepare-renderer [this list item _ selected _]
(.setOpaque this true)
(let [[bg fg] (if selected
[#(.getSelectionBackground %)
#(.getSelectionForeground %)]
[#(.getBackground %)
#(.getForeground %)])]
(.setBackground this (bg list))
(.setForeground this (fg list)))
(let [[item-type display-string _ _ _] item]
(.setIcon this (-> item-type item-type-names icons))
(.setFont this monospace-font)
(.setText this display-string))
this)
(def list-cell-renderer
(doto (-> (get-proxy-class JLabel ListCellRenderer)
(construct-proxy))
(init-proxy {"getListCellRendererComponent" prepare-renderer})))
(def list-cell-renderer
(proxy [JLabel ListCellRenderer] []
(getListCellRendererComponent [list item _ selected _]
(.setOpaque this true)
(let [[bg fg] (if selected
[#(.getSelectionBackground %)
#(.getSelectionForeground %)]
[#(.getBackground %)
#(.getForeground %)])]
(.setBackground this (bg list))
(.setForeground this (fg list)))
(let [[item-type display-string _ _ _] item]
(.setIcon this (-> item-type item-type-names icons))
(.setFont this monospace-font)
(.setText this display-string))
this)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment