question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SearchableComboBox Selection change event runs 3 times for each selection.

See original GitHub issue

Here I have tried to produce a minimalist example about the problem. Below code is in the Start method where I am showing difference between default and controlfx combox.

    @Override
    public void start(Stage stage) throws IOException {

        //List for the ComboBox.
        ObservableList<String> fontFamilies = FXCollections.observableArrayList(Font.getFamilies());

        SearchableComboBox<String> searchableComboBox = new SearchableComboBox();
        searchableComboBox.setItems(fontFamilies);
        searchableComboBox.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
            System.out.println();
            System.out.println("ControlFX");
            System.out.println("oldValue = " + oldValue);
            System.out.println("newValue = " + newValue);
        });

        //Default javafx ComboBox.
        ComboBox<String> javaFXDefault = new ComboBox<>();
        javaFXDefault.setItems(fontFamilies);
        javaFXDefault.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
            System.out.println();
            System.out.println("JavaFX Default");
            System.out.println("oldValue = " + oldValue);
            System.out.println("newValue = " + newValue);
        });

        //Scene and containers.
        VBox vBox = new VBox(searchableComboBox, javaFXDefault);
        Scene scene = new Scene(vBox, 320, 240);
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.show();

    }

And if i select a single item from the controlFX searchable combobox and default javafx one then below is the log for that :

ControlFX
oldValue = null
newValue = Arial Narrow

ControlFX
oldValue = Arial Narrow
newValue = null

ControlFX
oldValue = null
newValue = Arial Narrow

JavaFX Default
oldValue = null
newValue = Arial Narrow

You can see that we received three log for the SearchableCombox but one for the JavaFX default one. image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
1504168commented, Jan 25, 2022

I think the problem lies in the observable list. So when we do search in the searchable dropdown list then it’s dynamically change the item list from the dropdown based on keystroke. So if previously selected item is not present in the filtered list then it has to unselect and that’s firing that observable item selection event. Possible way to overwrite is make a shallow clone of the observable list once click on the SearchableComboBox and do those changes in the cloned observable list and then when the dropdown item list close then check whatever is selected in the cloned observable list and then fire ChangeListener on the original observable list with the finally chosen item. don’t know the whole implementation of this ControlFX SearchableCombobox but this approach may work.

0reactions
1504168commented, Feb 3, 2022

Hi @SaingHmineTun i couldn’t find any event which has hidden, showing in it and also that run multiple times like selection change event. Can you check it again plaease.

Read more comments on GitHub >

github_iconTop Results From Across the Web

KendoUI ComboBox Change Event Runs Multiple Times
Upon rendering, a page controller sets-up & shims-in its' own Change Event. Oddly, this event gets called TWICE: When I change the Selected...
Read more >
OnChange Combobox triggering many times
Thie combobox (DataCardValue28) has two choices, "Open" & "Closed". I want the OnChange fire only if value is changed to "Closed".
Read more >
Addin ComboBox OnSelChange fires multiple times wi...
Going off memory, on selection changed event will get fired several times. For instance if a layer get selected and another one de-selected...
Read more >
Combo box events are firing two times - Telerik
If you run the example you will notice that with the custom logic in the change event handlers commented a selection in the...
Read more >
Events | Select2 - The jQuery replacement for select boxes
Scoped version of change . See below for more details. select2:closing, Triggered before the dropdown is closed. This event can be prevented.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found