0

How do we fetch a row from a tableview in javafx ? We have a tableview with a column which holds checkboxes. Based on the checkbox selection, we have to mark a row in grey. How do we do it ?? Any help would be appreciated!

We tried the following piece of code

table1 = name of tableview

Column zero is the column with checkbox whose value has to be retrieved and based on which we have to highlight in grey

    TableColumn calltypel = table1.getColumns().get(0);
    calltypel.setCellFactory(column -> {
    return new TableCell<Data, Boolean>() {
        @Override
        protected void updateItem(Boolean item, boolean empty) {
            super.updateItem(item, empty);

            setText(empty ? "" : getItem().toString());

            TableRow<Data> currentRow = getTableRow();


            if (!isEmpty()) {

                if(item)
                    currentRow.setStyle("-fx-background-color:#C3C3C3;");

                table1.setStyle("-fx-border-color: #A6A6A6; -fx-border-width:1px ;");
            } 
        }
    };
});

Our aim is : We have to tick few rows and then click on a button say "Done" and post that it should remain grey until close of the application.

The above code works but this leads to a permanent binding. we tick a checkbox and then click on Done, the row turns grey. After that the binding is permanent , i.e.,the moment we check the checkbox, its grey and on unchecking its white/pink as per the original table row column.

Please help !

  • What have you tried already and what isn't working? Are you looking to override normal row selection with your own solution? – purring pigeon Jul 20 '17 at 05:25
  • [Please complete a [mcve] and check out [ask] – Hypnic Jerk Jul 20 '17 at 05:27
  • Also related, though it is slightly different because it is based upon a ListView, is: [JavaFx list View coloring the list cell](https://stackoverflow.com/questions/45067838/javafx-list-view-coloring-the-list-cell) – jewelsea Jul 20 '17 at 17:58

0 Answers0