Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you don't want the reusability of the solution I posted above, this is really the same thing but using an anonymous inner class for the row factory instead of a standalone class. Perhaps the code is easier to follow as it's all in one place. It's kind of a hybrid between Jonathan's solution and mine, but will automatically update the highlights without forcing it with a sort. </p> <p>I used a list of integers so it supports multiple selection, but if you don't need that you could obviously just use an IntegerProperty instead.</p> <p>Here's the row factory:</p> <pre><code> final ObservableList&lt;Integer&gt; highlightRows = FXCollections.observableArrayList(); table.setRowFactory(new Callback&lt;TableView&lt;Person&gt;, TableRow&lt;Person&gt;&gt;() { @Override public TableRow&lt;Person&gt; call(TableView&lt;Person&gt; tableView) { final TableRow&lt;Person&gt; row = new TableRow&lt;Person&gt;() { @Override protected void updateItem(Person person, boolean empty){ super.updateItem(person, empty); if (highlightRows.contains(getIndex())) { if (! getStyleClass().contains("highlightedRow")) { getStyleClass().add("highlightedRow"); } } else { getStyleClass().removeAll(Collections.singleton("highlightedRow")); } } }; highlightRows.addListener(new ListChangeListener&lt;Integer&gt;() { @Override public void onChanged(Change&lt;? extends Integer&gt; change) { if (highlightRows.contains(row.getIndex())) { if (! row.getStyleClass().contains("highlightedRow")) { row.getStyleClass().add("highlightedRow"); } } else { row.getStyleClass().removeAll(Collections.singleton("highlightedRow")); } } }); return row; } }); </code></pre> <p>And here are what some buttons might look like:</p> <pre><code> final Button btnHighlight = new Button("Highlight"); btnHighlight.disableProperty().bind(Bindings.isEmpty(table.getSelectionModel().getSelectedIndices())); btnHighlight.setOnAction(new EventHandler&lt;ActionEvent&gt;() { @Override public void handle(ActionEvent event) { highlightRows.setAll(table.getSelectionModel().getSelectedIndices()); } }); final Button btnClearHighlight = new Button("Clear Highlights"); btnClearHighlight.disableProperty().bind(Bindings.isEmpty(highlightRows)); btnClearHighlight.setOnAction(new EventHandler&lt;ActionEvent&gt;() { @Override public void handle(ActionEvent event) { highlightRows.clear(); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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