Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combo-box updating it's items but not it's selected item #102

Closed
torkus opened this issue Sep 30, 2020 · 3 comments
Closed

combo-box updating it's items but not it's selected item #102

torkus opened this issue Sep 30, 2020 · 3 comments
Labels
has workaround Does not limit users javafx Something isn't working in JavaFX question Not an actual issue, a question

Comments

@torkus
Copy link

torkus commented Sep 30, 2020

I have a combo-box that will update it's items but not it's label, resulting in a combo-box with a blank label.

It's easy to recreate and I have an example here:

git clone https://github.com/ogri-la/cljfx-issues
cd cljfx-issues
lein run

In the example there are three combo-boxes each configured slightly differently but all failing to render their label when the underlying list of items changes.

@vlaaad vlaaad added has workaround Does not limit users javafx Something isn't working in JavaFX question Not an actual issue, a question labels Oct 3, 2020
@vlaaad
Copy link
Contributor

vlaaad commented Oct 3, 2020

Hmm, I thought specifying :button-cell and :cell-factory should be enough for combo-boxes, but apparently it's not — I reproduced the issue. It seems that the combo-box value gets silently reset to nil when :items change.

A workaround is ext-recreate-on-key-changed lifecycle described here, where :key should be the same value as in :items.

Example using this lifecycle:

(def state
  (atom {:values {:one "one"
                  :two "two"}
         :selected :one}))

(fx/mount-renderer
  state
  (fx/create-renderer
    :middleware
    (fx/wrap-map-desc
      (fn [{:keys [values selected] :as in}]
        {:fx/type :stage
         :showing true
         :width 600
         :height 500
         :scene
         {:fx/type :scene
          :root
          {:fx/type :v-box
           :children
           [{:fx/type ext-recreate-on-key-changed
             :key (sort-by key values)
             :desc {:fx/type :combo-box
                    :button-cell (fn [e] {:text (val e)})
                    :cell-factory {:fx/cell-type :list-cell
                                   :describe (fn [e] {:text (val e)})}
                    :value (find values selected)
                    :on-value-changed (fn [e] (swap! state assoc :selected (key e)))
                    :items (sort-by key values)}}
            {:fx/type :button
             :text "Add"
             :on-action (fn [_] (swap! state update :values assoc :three "three"))}
            {:fx/type :button
             :text "Remove"
             :on-action (fn [_] (swap! state update :values dissoc :three))}
            {:fx/type :label
             :text (with-out-str (clojure.pprint/pprint in))}]}}}))))

@torkus
Copy link
Author

torkus commented Oct 7, 2020

thanks for this @vlaaad , it fixes the problem I was having. I was also able to remove :cell-factory and :button-cell and have it work simply again across linux and mac.

@vlaaad
Copy link
Contributor

vlaaad commented Jan 1, 2021

Fixed for good in 1.7.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround Does not limit users javafx Something isn't working in JavaFX question Not an actual issue, a question
Projects
None yet
Development

No branches or pull requests

2 participants