A certain misunderstanding bubbled up in a recent QA at Stackoverflow: https://stackoverflow.com/a/70371971/203657
The doc states that both text and graphic have to be nulled for empty cells. That's not quite correct: if we don't touch graphic in the not-empty block, there is no reason to null it in the empty block.
Current code example:
@Override protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
setText(item.toString());
}
}
Current text:
We test for the empty condition, and if true, we set the text and graphic properties to null. If we do not do this, it is almost guaranteed that end users will see graphical artifacts in cells unexpectedly.
Introduced inJDK-8095003.
The text should emphasize that the not-/empty blocks need to be symmetric, something like:
.. if true, we have to reset (to null or a reasonable default) every property that has been set in the not empty case ..
The code example could then either set the graphic along with the text or not null it:
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
} else {
setText(item.toString());
}
or:
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
setText(item.toString());
setGraphic(myGraphic)
}
The doc states that both text and graphic have to be nulled for empty cells. That's not quite correct: if we don't touch graphic in the not-empty block, there is no reason to null it in the empty block.
Current code example:
@Override protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
setText(item.toString());
}
}
Current text:
We test for the empty condition, and if true, we set the text and graphic properties to null. If we do not do this, it is almost guaranteed that end users will see graphical artifacts in cells unexpectedly.
Introduced in
The text should emphasize that the not-/empty blocks need to be symmetric, something like:
.. if true, we have to reset (to null or a reasonable default) every property that has been set in the not empty case ..
The code example could then either set the graphic along with the text or not null it:
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
} else {
setText(item.toString());
}
or:
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
setText(item.toString());
setGraphic(myGraphic)
}
- relates to
-
JDK-8095003 [ListView] Deleting items from ListView with setCellFactory causes unexpected displaying behaviour
-
- Closed
-