-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
jfx11, 8, 9, 10
-
x86_64
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
4.13.0-36-generic #40-Ubuntu SMP Fri Feb 16 20:07:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
I extended SimpleObjectProperty<T> to create a custom, lazy-loading implementation, LazyLoadingObjectProperty<T>.
To use this generic implementation for a boolean property, I use LazyLoadingObjectProperty<Boolean>.
In my table, I want to render the boolean property as a CheckBox.
Nevertheless, CheckBoxTableCell seems to work only with BooleanProperty but not with ObjectProperty<Boolean>.
See also here:
https://stackoverflow.com/questions/49154386/checkboxtablecell-not-working-with-objectpropertyboolean
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the SO question, there is also a MWE.
Thanks!
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class ExampleTable extends Application {
private static final int NUM_ELEMENTS = 5000;
private final TableView<ExampleBean> table = new TableView<>();
private final ObservableList<ExampleBean> data = FXCollections.observableArrayList();
public static void main(final String[] args) {
launch(args);
}
@Override
public void start(final Stage stage) {
final Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
stage.setWidth(300);
stage.setHeight(500);
final TableColumn<ExampleBean, Boolean> c1 = new TableColumn<>("A");
c1.setCellValueFactory(new PropertyValueFactory<ExampleBean, Boolean>("p1"));
c1.setCellFactory(CheckBoxTableCell.forTableColumn(c1));
c1.setEditable(true);
c1.setPrefWidth(100);
final TableColumn<ExampleBean, String> c2 = new TableColumn<>("B");
c2.setCellValueFactory(new PropertyValueFactory<ExampleBean, String>("p2"));
c2.setCellFactory(TextFieldTableCell.forTableColumn());
c2.setEditable(true);
c2.setPrefWidth(100);
for (int i = 0; i < NUM_ELEMENTS; i++) {
data.add(new ExampleBean());
}
final ScrollPane sp = new ScrollPane();
sp.setContent(table);
sp.setMaxHeight(Double.POSITIVE_INFINITY);
sp.setMaxWidth(Double.POSITIVE_INFINITY);
sp.setFitToHeight(true);
sp.setFitToWidth(true);
table.setEditable(true);
table.setItems(data);
// table.setMaxHeight(Double.POSITIVE_INFINITY);
// table.setMaxWidth(Double.POSITIVE_INFINITY);
table.getColumns().addAll(c1, c2);
final ContextMenu cm = new ContextMenu();
cm.getItems().add(new MenuItem("bu"));
table.setContextMenu(cm);
final VBox vbox = new VBox();
vbox.setSpacing(5);
VBox.setVgrow(sp, Priority.ALWAYS);
vbox.getChildren().addAll(sp);
scene.setRoot(vbox);
stage.setScene(scene);
stage.show();
}
}
public class ExampleBean {
private ObjectProperty<Boolean> p1;
private ObjectProperty<String> p2;
public ExampleBean() {
p1 = new SimpleObjectProperty(true);
p1.addListener((o, ov, nv) -> {
System.err.println("Value changed " + ov + " -> " + nv);
});
p2 = new SimpleObjectProperty(Integer.toString(new Random().nextInt()));
p2.addListener((o, ov, nv) -> {
System.err.println("Value changed " + ov + " -> " + nv);
});
}
public final ObjectProperty<Boolean> p1Property() {
return this.p1;
}
public final ObjectProperty<String> p2Property() {
return this.p2;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Bidi-bind the ObjectProperty<Boolean> to BooleanProperty and use this one in the table.
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
4.13.0-36-generic #40-Ubuntu SMP Fri Feb 16 20:07:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
I extended SimpleObjectProperty<T> to create a custom, lazy-loading implementation, LazyLoadingObjectProperty<T>.
To use this generic implementation for a boolean property, I use LazyLoadingObjectProperty<Boolean>.
In my table, I want to render the boolean property as a CheckBox.
Nevertheless, CheckBoxTableCell seems to work only with BooleanProperty but not with ObjectProperty<Boolean>.
See also here:
https://stackoverflow.com/questions/49154386/checkboxtablecell-not-working-with-objectpropertyboolean
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the SO question, there is also a MWE.
Thanks!
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class ExampleTable extends Application {
private static final int NUM_ELEMENTS = 5000;
private final TableView<ExampleBean> table = new TableView<>();
private final ObservableList<ExampleBean> data = FXCollections.observableArrayList();
public static void main(final String[] args) {
launch(args);
}
@Override
public void start(final Stage stage) {
final Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
stage.setWidth(300);
stage.setHeight(500);
final TableColumn<ExampleBean, Boolean> c1 = new TableColumn<>("A");
c1.setCellValueFactory(new PropertyValueFactory<ExampleBean, Boolean>("p1"));
c1.setCellFactory(CheckBoxTableCell.forTableColumn(c1));
c1.setEditable(true);
c1.setPrefWidth(100);
final TableColumn<ExampleBean, String> c2 = new TableColumn<>("B");
c2.setCellValueFactory(new PropertyValueFactory<ExampleBean, String>("p2"));
c2.setCellFactory(TextFieldTableCell.forTableColumn());
c2.setEditable(true);
c2.setPrefWidth(100);
for (int i = 0; i < NUM_ELEMENTS; i++) {
data.add(new ExampleBean());
}
final ScrollPane sp = new ScrollPane();
sp.setContent(table);
sp.setMaxHeight(Double.POSITIVE_INFINITY);
sp.setMaxWidth(Double.POSITIVE_INFINITY);
sp.setFitToHeight(true);
sp.setFitToWidth(true);
table.setEditable(true);
table.setItems(data);
// table.setMaxHeight(Double.POSITIVE_INFINITY);
// table.setMaxWidth(Double.POSITIVE_INFINITY);
table.getColumns().addAll(c1, c2);
final ContextMenu cm = new ContextMenu();
cm.getItems().add(new MenuItem("bu"));
table.setContextMenu(cm);
final VBox vbox = new VBox();
vbox.setSpacing(5);
VBox.setVgrow(sp, Priority.ALWAYS);
vbox.getChildren().addAll(sp);
scene.setRoot(vbox);
stage.setScene(scene);
stage.show();
}
}
public class ExampleBean {
private ObjectProperty<Boolean> p1;
private ObjectProperty<String> p2;
public ExampleBean() {
p1 = new SimpleObjectProperty(true);
p1.addListener((o, ov, nv) -> {
System.err.println("Value changed " + ov + " -> " + nv);
});
p2 = new SimpleObjectProperty(Integer.toString(new Random().nextInt()));
p2.addListener((o, ov, nv) -> {
System.err.println("Value changed " + ov + " -> " + nv);
});
}
public final ObjectProperty<Boolean> p1Property() {
return this.p1;
}
public final ObjectProperty<String> p2Property() {
return this.p2;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Bidi-bind the ObjectProperty<Boolean> to BooleanProperty and use this one in the table.
- duplicates
-
JDK-8090285 CheckBoxTableCell.forTableColumn() incompatible with ObjectProperty<Boolean>
-
- Open
-