Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i add event handlers to checkboxes in a listview checkbox cell?
    primarykey
    data
    text
    <p>I am creating a list of cards that users can select from to start a game. Users select their cards by a checkbox next to the card name, and they are only allowed to select 10 cards. I want to be able to limit the number of checkboxes that can be selected by having an event handler get called when a checkbox is clicked and determine whether the checkbox is allowed to be clicked or not. How can i add an event handler to every checkbox to do this? If there is a better way, i am definitely open to suggestions. Here is my code where i setup the listview and the checkbox callback:</p> <pre><code>ListView&lt;Card&gt; cards; Callback&lt;Card, ObservableValue&lt;Boolean&gt;&gt; checkBoxCallback = new Callback&lt;Card, ObservableValue&lt;Boolean&gt;&gt;() { @Override public BooleanProperty call(Card card) { return card.selectedProperty(); } }; StringConverter&lt;Card&gt; cardToStringConverter = new StringConverter&lt;Card&gt;() { @Override public Card fromString(String card) { try { return CardFactory.createCard(card); } catch (Exception e) { e.printStackTrace(); } return null; } @Override public String toString(Card card) { return card.toString(); } }; Callback&lt;ListView&lt;Card&gt;, ListCell&lt;Card&gt;&gt; listViewCallback = CheckBoxListCell.forListView(checkBoxCallback, cardToStringConverter); cards.setCellFactory(listViewCallback); cards.getSelectionModel().selectedItemProperty().addListener(new ChangeListener&lt;Card&gt;() { @Override public void changed(ObservableValue&lt;? extends Card&gt; obsValue, Card oldValue, Card newValue) { cardImageView.setImage(newValue.getCardImage()); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload