Re: ComboBox: TestEditor to ListView binding
Kirill, ControlsFX has support for this if a 3rd party lib is ok. With TextFields.createClearableTextField() you create a search field with an eraser icon to clear the text. And the AutoCompletionBinding applied to the textfield implements the auto complete dropdown. You only have to provide a function to return search results for user input. Werner On 04.07.2014 23:48, Kirill Kirichenko wrote: I'm implementing a searchbox. In the textfield of the combobox I'm typing a search string. textProperty of the editor has an onChange listener which forms a list of strings that contain the text as a substring. Then I set this list of strings as a content of the drop down list of the combobox. The problem is when I start selecting items in the drop down list the editor field gets updated making new substring search and updating the list again. I want to break this dependency. I don't want to update the text property when I select an item in the drop down list OR I want to distinguish in the textProperty listener what caused that event - real editing the field or setting the field trough binding from the list view. I hope I could make myself clear. K
Re: ComboBox: TestEditor to ListView binding
I'm afraid in my project I will only allowed to use vanilla javafx only. It would be good if someone could write a blog of how to create a bare minimum combobox control with desired behaviour like I explained. Thanks for the reference. K On 07.07.2014 11:20, Werner Lehmann wrote: Kirill, ControlsFX has support for this if a 3rd party lib is ok. With TextFields.createClearableTextField() you create a search field with an eraser icon to clear the text. And the AutoCompletionBinding applied to the textfield implements the auto complete dropdown. You only have to provide a function to return search results for user input. Werner On 04.07.2014 23:48, Kirill Kirichenko wrote: I'm implementing a searchbox. In the textfield of the combobox I'm typing a search string. textProperty of the editor has an onChange listener which forms a list of strings that contain the text as a substring. Then I set this list of strings as a content of the drop down list of the combobox. The problem is when I start selecting items in the drop down list the editor field gets updated making new substring search and updating the list again. I want to break this dependency. I don't want to update the text property when I select an item in the drop down list OR I want to distinguish in the textProperty listener what caused that event - real editing the field or setting the field trough binding from the list view. I hope I could make myself clear. K
Re: ComboBox: TestEditor to ListView binding
Hi Kirill, I looked at this again quickly and while there might be a combination of events and listeners that can make a combo box behave this way, you are better to create your own search box and manage the popup list. The reason for this is that any code you are likely to write that manipulates the combo box will be sensitive to event ordering. There is an example of a search field as part of EnsembleApp. It is quite complicated and fancy and is mixed in with EnsembleApp code so you might have to work a bit to extract a simpler version of what you are looking for. Hopefully Jasper is reading this right now and can whip up a hundred lines of code or so that do what you want. Steve On 2014-07-04, 5:48 PM, Kirill Kirichenko wrote: I'm implementing a searchbox. In the textfield of the combobox I'm typing a search string. textProperty of the editor has an onChange listener which forms a list of strings that contain the text as a substring. Then I set this list of strings as a content of the drop down list of the combobox. The problem is when I start selecting items in the drop down list the editor field gets updated making new substring search and updating the list again. I want to break this dependency. I don't want to update the text property when I select an item in the drop down list OR I want to distinguish in the textProperty listener what caused that event - real editing the field or setting the field trough binding from the list view. I hope I could make myself clear. K On 05.07.2014 01:21, Stephen F Northover wrote: Hi Kirill, What exactly are you trying to do? The following (crap) listens for the value to change and then sets it back: ChangeListenerString l = new ChangeListenerString () { public void changed(ObservableValue observable, String oldValue, String newValue) { System.out.println(attempt to set new value: + newValue); Platform.runLater(() - { comboBox3.valueProperty().removeListener(this); System.out.println(restoring old value: + newValue); comboBox3.setValue(oldValue); comboBox3.valueProperty().addListener(this); }); }; }; comboBox3.valueProperty().addListener(l); This is not good code because it adds and removes a listener to avoid notification when the value is reset. It uses runLater() in order to stop the combo box from getting confused when the value is changed from within a changed listener. Steve On 2014-07-04, 3:09 PM, Kirill Kirichenko wrote: JavaFX ComboBox has binding between TextEdit field and the ListView selection such that edit field gets updated when we change the selected item in the drop down list. Is there a way to break this binding - when we select an item in the list the editor field remains untouched. Where should I look at ? Thanks. K
ComboBox: TestEditor to ListView binding
JavaFX ComboBox has binding between TextEdit field and the ListView selection such that edit field gets updated when we change the selected item in the drop down list. Is there a way to break this binding - when we select an item in the list the editor field remains untouched. Where should I look at ? Thanks. K
Re: ComboBox: TestEditor to ListView binding
Hi Kirill, What exactly are you trying to do? The following (crap) listens for the value to change and then sets it back: ChangeListenerString l = new ChangeListenerString () { public void changed(ObservableValue observable, String oldValue, String newValue) { System.out.println(attempt to set new value: + newValue); Platform.runLater(() - { comboBox3.valueProperty().removeListener(this); System.out.println(restoring old value: + newValue); comboBox3.setValue(oldValue); comboBox3.valueProperty().addListener(this); }); }; }; comboBox3.valueProperty().addListener(l); This is not good code because it adds and removes a listener to avoid notification when the value is reset. It uses runLater() in order to stop the combo box from getting confused when the value is changed from within a changed listener. Steve On 2014-07-04, 3:09 PM, Kirill Kirichenko wrote: JavaFX ComboBox has binding between TextEdit field and the ListView selection such that edit field gets updated when we change the selected item in the drop down list. Is there a way to break this binding - when we select an item in the list the editor field remains untouched. Where should I look at ? Thanks. K
Re: ComboBox: TestEditor to ListView binding
I'm implementing a searchbox. In the textfield of the combobox I'm typing a search string. textProperty of the editor has an onChange listener which forms a list of strings that contain the text as a substring. Then I set this list of strings as a content of the drop down list of the combobox. The problem is when I start selecting items in the drop down list the editor field gets updated making new substring search and updating the list again. I want to break this dependency. I don't want to update the text property when I select an item in the drop down list OR I want to distinguish in the textProperty listener what caused that event - real editing the field or setting the field trough binding from the list view. I hope I could make myself clear. K On 05.07.2014 01:21, Stephen F Northover wrote: Hi Kirill, What exactly are you trying to do? The following (crap) listens for the value to change and then sets it back: ChangeListenerString l = new ChangeListenerString () { public void changed(ObservableValue observable, String oldValue, String newValue) { System.out.println(attempt to set new value: + newValue); Platform.runLater(() - { comboBox3.valueProperty().removeListener(this); System.out.println(restoring old value: + newValue); comboBox3.setValue(oldValue); comboBox3.valueProperty().addListener(this); }); }; }; comboBox3.valueProperty().addListener(l); This is not good code because it adds and removes a listener to avoid notification when the value is reset. It uses runLater() in order to stop the combo box from getting confused when the value is changed from within a changed listener. Steve On 2014-07-04, 3:09 PM, Kirill Kirichenko wrote: JavaFX ComboBox has binding between TextEdit field and the ListView selection such that edit field gets updated when we change the selected item in the drop down list. Is there a way to break this binding - when we select an item in the list the editor field remains untouched. Where should I look at ? Thanks. K