Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8133699

CheckBoxTableCell cannot handle properties based on ObjectProperty<Boolean>

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • 9
    • 8u51
    • javafx
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      A DESCRIPTION OF THE PROBLEM :
      CheckBoxTableCell cannot handle properties based on ObjectProperty<Boolean>. If the property is based on BooleanProperty and it works fine.
      See sample code: The table column "Vegetarian" is based on BooleanProperty, the column "Vegetarian1" on ObjectProperty<Boolean>.



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.beans.property.BooleanProperty;
      import javafx.beans.property.ObjectProperty;
      import javafx.beans.property.SimpleBooleanProperty;
      import javafx.beans.property.SimpleObjectProperty;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.collections.FXCollections;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.CheckBoxTableCell;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class CheckBoxTableCellTest extends Application {

          @Override
          public void start(Stage primaryStage) {
              final TableView<Person> tableView = new TableView<Person>();
              tableView.setItems(FXCollections.observableArrayList(
                      new Person("Robert", "Plant"),
                      new Person("Neil", "Young"),
                      new Person("Willie", "Nelson"),
                      new Person("Natalie", "Merchant")
              ));
              tableView.getItems().get(3).setVegetarian(true);
              tableView.getItems().get(3).setVegetarian1(true);

              final TableColumn<Person, String> firstNameCol = new TableColumn<Person, String>("First Name");
              final TableColumn<Person, String> lastNameCol = new TableColumn<Person, String>("Last Name");
              final TableColumn<Person, Boolean> vegetarianCol = new TableColumn<Person, Boolean>("Vegetarian");
              final TableColumn<Person, Boolean> vegetarian1Col = new TableColumn<Person, Boolean>("Vegetarian1");
              
              tableView.getColumns().addAll(firstNameCol, lastNameCol, vegetarianCol, vegetarian1Col);
              firstNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
              lastNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));

              vegetarianCol.setCellFactory(CheckBoxTableCell.forTableColumn(vegetarianCol));
              vegetarianCol.setCellValueFactory(new PropertyValueFactory<Person, Boolean>("vegetarian"));
              vegetarianCol.setEditable(true);
              
              vegetarian1Col.setCellFactory(CheckBoxTableCell.forTableColumn(vegetarian1Col));
              vegetarian1Col.setCellValueFactory(new PropertyValueFactory<Person, Boolean>("vegetarian1"));
              vegetarian1Col.setEditable(true);
              
              tableView.setEditable(true);

              final BorderPane root = new BorderPane();
              root.setCenter(tableView);

              final HBox controls = new HBox(5);
              final Button infoButton = new Button("Show details");
              infoButton.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      for (Person p : tableView.getItems())
                          System.out.println(String.format("%s %s %s %s", p.getFirstName(), p.getLastName(), p.isVegetarian(), p.isVegetarian1()));
                      System.out.println();
                  }
              });
              controls.getChildren().add(infoButton);
              root.setBottom(controls);

              Scene scene = new Scene(root, 320, 400);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }

          public static class Person {

              private StringProperty firstName;
              private StringProperty lastName;
              private BooleanProperty vegetarian;
              private final ObjectProperty<Boolean> vegetarian1;

              public Person(String firstName, String lastName) {
                  this.firstName = new SimpleStringProperty(firstName);
                  this.lastName = new SimpleStringProperty(lastName);
                  this.vegetarian = new SimpleBooleanProperty(false);
                  this.vegetarian1 = new SimpleObjectProperty(false);
              }

              public Boolean isVegetarian1() {
                  return vegetarian1.get();
              }

              public void setVegetarian1(Boolean value) {
                  vegetarian1.set(value);
              }

              public ObjectProperty vegetarian1Property() {
                  return vegetarian1;
              }

              public String getFirstName() {
                  return firstName.get();
              }

              public String getLastName() {
                  return lastName.get();
              }

              public boolean isVegetarian() {
                  return vegetarian.get();
              }

              public void setFirstName(String firstName) {
                  this.firstName.set(firstName);
              }

              public void setLastName(String lastName) {
                  this.lastName.set(lastName);
              }

              public void setVegetarian(boolean vegetarian) {
                  this.vegetarian.set(vegetarian);
              }

              public StringProperty firstNameProperty() {
                  return firstName;
              }

              public StringProperty lastNameProperty() {
                  return lastName;
              }

              public BooleanProperty vegetarianProperty() {
                  return vegetarian;
              }
          }
      }

      ---------- END SOURCE ----------

            jgiles Jonathan Giles
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: