r/JavaFX • • Jan 21 '25

Help How to clear an ItemView?

I'm working on a UI part, which is basically a list of directories and its contents

Whenever you select the ChoiceBox, there is a list of subfolders.

I have a ChangeListener hooked up to ChoiceBox, which basically calls

listView.getItems().clear();
listView.getItems().addAll(...);
listView.refresh();

If I'm switching content of listView from 10 elements to 3 (from `Interrogator` to `Pariah Nexus`) I'm getting leftovers.

And the leftovers are not clickable. Just a graphical glitch.

How to address this?

1 Upvotes

10 comments sorted by

View all comments

Show parent comment

0

u/Draaksward_89 Jan 21 '25
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {

This is what I overlooked. Thank you.

For the c/c++ code styles. Yes, I know (have been with java for quite a few years, but JavaFX is mostly new), still figuring out the best naming approach that would visually be informative for me (and not just right in terms of code conventions).