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

1

u/Draaksward_89 Jan 21 '25

selectedItemProperty.subscribe(newItem-> ...)

Hm. Need to try this. Thanks.

Generally, my issue was with CellFactory (forgot the if null case).