Fork me on GitHub
#cljfx
<
2021-10-17
>
thom21:10:59

should I expect setting a :style-class in a :cell-factory (in a table view in this case) to work? I'm not seeing them getting set properly right now. I'm led to believe JavaFX does allow individual cells to have their own classes.

vlaaad09:10:19

I would expect style classes to work, can you share an example?

vlaaad09:10:25

This works for me:

(require '[cljfx.css :as css]
         '[cljfx.api :as fx])

(def css-url
  (::css/url (css/register ::css {".red" {:-fx-text-fill :red}
                                  ".green" {:-fx-text-fill :green}})))

(fx/on-fx-thread
  (fx/create-component
    {:fx/type :stage
     :showing true
     :scene {:fx/type :scene
             :stylesheets [css-url]
             :root {:fx/type :table-view
                    :columns [{:fx/type :table-column
                               :cell-value-factory identity
                               :cell-factory {:fx/cell-type :table-cell
                                              :describe (fn [x]
                                                          {:text (str x)
                                                           :style-class (name x)})}}]
                    :items [:red :green]}}}))

thom09:10:09

Ahh, I'm setting it one level up alongside the cell type. That explains it, thanks!

👍 1