JavaFX dropbox update delay issue

Overview

JavaFX ChoiceBox instance (I expect the same for ComboBox) Occurs when swapping the choice list of Delays and increased memory usage were issues.

environment

Win10 Java8

What is a drop box

Click to select and a list will appear. It is a standard part in GUI, but what should I call it? It's also called "dropdown" or "pulldown". In JavaFX, an instance of a class called ChoiceBox becomes a single dropbox.

Symptoms

Set a list of items to choose from.

I have a string list of about 1000 (!) ChoiceBox.getItems (). AddAll (items); I handed it over. Then If this operation is performed when the choiceBox is already displayed on the scene graph, ・ The entire GUI freezes in tens of seconds -The amount of memory used increases in units of 500MB or several GB.

Perhaps the listener will work to access the scenegraph each time one item in the list is added. Does that mean you shouldn't set 1000 pieces?

However, there is no problem even if 1000 pieces are set before the choiceBox is displayed.


Until the choiceBox is drawn even once. The symptom did not change even if it was setVisible (false); or removed from the parent node to hide it.

↑ I don't understand this. Why can't I disable graph updates?

I also tried the method of resetting the ObservableList from the method of choiceBox.setItems () ;. This method seems to be valid only the first time.

Conclusion

I tried various things It seems to be the most decent to make the ChoiceBox instance disposable and "do not update the list for the instance after it is displayed in the scene graph".

I want to make choiceBox final, but I will give up for the time being.

Blurred

Java Spending time on these experiments stops progress. Am I doing something wrong?

Recommended Posts

JavaFX dropbox update delay issue