Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckbox cell factory + Tableview on JavaFX
    primarykey
    data
    text
    <p>I'm writing a JavaFX client for my soap service, and of my fxml pages must contain a fully-editable TableView, which consists of Product-class entities.My table consists now of 2 text columns and one, which consists of Double values.I want to add a selection column with CheckBox items in it cells.Using a Ensemble demo app I extended a Cell class for using a CheckBoxes :</p> <pre><code>public class CheckBoxCell&lt;S, T&gt; extends TableCell&lt;S, T&gt; { private final CheckBox checkBox; private ObservableValue&lt;T&gt; ov; public CheckBoxCell() { this.checkBox = new CheckBox(); this.checkBox.setAlignment(Pos.CENTER); setAlignment(Pos.CENTER); setGraphic(checkBox); } @Override public void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (empty) { setText(null); setGraphic(null); } else { setGraphic(checkBox); if (ov instanceof BooleanProperty) { checkBox.selectedProperty().unbindBidirectional((BooleanProperty) ov); } ov = getTableColumn().getCellObservableValue(getIndex()); if (ov instanceof BooleanProperty) { checkBox.selectedProperty().bindBidirectional((BooleanProperty) ov); } } } @Override public void startEdit() { super.startEdit(); if (isEmpty()) { return; } checkBox.setDisable(false); checkBox.requestFocus(); } @Override public void cancelEdit() { super.cancelEdit(); checkBox.setDisable(true); } } </code></pre> <p>Then in fxml view controller class I set a cellFactory for requed TableColumn :</p> <pre><code>private Callback&lt;TableColumn, TableCell&gt; createCheckBoxCellFactory() { Callback&lt;TableColumn, TableCell&gt; cellFactory = new Callback&lt;TableColumn, TableCell&gt; () { @Override public TableCell call(TableColumn p) { return new CheckBoxCell(); } }; return cellFactory; } ... products_table_remove.setCellFactory(createCheckBoxCellFactory()); </code></pre> <p>My question is :</p> <p>1) how to fill this column with unchecked CheckBoxes using PropertyValueFactory if i have </p> <pre><code>private final ObservableList &lt;Boolean&gt; productsToRemove= FXCollections.observableArrayList(); </code></pre> <p>consists of Boolean.FALSE values then view is created. (TableView consists of Product class that does'nt have a Boolean property (only 3 String and one Double property)) ?</p> <p>2) Can i get acess to Product object, which contain selected row using EventHandler :</p> <pre><code>private void setProductDescColumnCellHandler() { products_table_remove.setOnEditCommit(new EventHandler() { @Override public void handle(CellEditEvent t) { ... </code></pre> <p>I saw a lot of examples with Entites, which have a Boolean field.In my case, i dont want to add boolean field to jax-ws generated classes. </p>
    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. 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