4

I'm attempting to make an auto complete combo box in javafx, but I'm having an issue that I can't seem to solve.

When a user presses the up or down arrow when the combo box is showing, it changes the selected item. Is there anyway disable this functionality such that when an up or down arrow is pressed, it still "highlights" the next or previous item, but doesn't actually change the selection model?

It seems that the arrow key pressed is being registered as an ActionEvent but consuming this event doesn't actually stop the selection from changing.

Any insight would be greatly appreciated, and I can give a SSCE if necessary.

thatjavaguy09
  • 222
  • 3
  • 13
  • 1
    That is how native comboboxes behave in Windows and Gnome. (I don't have a Mac with which to check on this.) It's generally not a good idea to alter the behavior of a standard UI control, because users feel most comfortable with consistency and predictability. An auto-complete field may have a drop-down list under it, but it's not really a combobox; perhaps you should manage your own [PopupControl](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/PopupControl.html) instead. – VGR Jul 09 '14 at 20:42
  • Thanks for the response. Do you think it would make more sense to create my own custom control which extends ComboBoxBase and give it it's own skin and behavior? If so do you have any examples on making your own control out of control - skin - behavior? Not too many good examples online about it. – thatjavaguy09 Jul 11 '14 at 13:46
  • In the documentation for ComboBoxBase, the very first property listed is `armed`. Since that doesn't apply to an auto-complete field, I wouldn't try to use that class. You may want to look at [this question](http://stackoverflow.com/questions/19924852/autocomplete-combobox-in-javafx), [this one](http://stackoverflow.com/questions/12927504/how-to-make-an-autocomplete-combobox-in-javafx-2-x-using-modern-fxml-and-contro), and https://www.versioneye.com/java/org.rapidpm.modul:javafx-autocomplete-textfield/1.2 . I have not tried any of these so I don't know how well they work. – VGR Jul 11 '14 at 13:55
  • Sorry, I probably should have explained my problem a little further. I'm looking to make an auto complete combo box, not an auto complete text field or search box. As the user types, it should still provide a drop down of related items. I would say I want like 85% of the functionality that a combo box provides, just not the selection changing on arrow key press. Does that make more sense and does it make sense to extend ComboBoxBase in this situation and provide my own behavior? – thatjavaguy09 Jul 11 '14 at 14:30
  • 1
    You could try [ChoiceBox](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ChoiceBox.html), which is functionally the same but has slightly different behavior; the arrow keys don't immediately change the selection. If that isn't acceptable, then based on my understanding of your need, I would choose to let ComboBox operate as it normally operates. That is what users will expect. Designing a brand new control is harder than it sounds. For what it's worth, that a ComboBox lets the user drop down the list with Alt-↓. – VGR Jul 11 '14 at 21:39
  • I would also suggest rolling your own solution for it. I've recently programmed a auto-completing combo-esque input widget myself (sorry, closed source project) which basically combines a TextField, a Button and a ListView to achieve what I wanted. I tried to customize ComboBox first but there were too many little details that just did not behave the way I wanted. – rli Nov 13 '14 at 14:00
  • i found a solution. did u fix your issue? – Eshaka Mar 28 '20 at 05:58
  • I have the same problem as you @thatjavaguy09. I do not agree that combobox do or should behave like this. Actually the regular expectation of a ComboBox is that when you edit text, you actually enter a filter on the items shown in the drop-down. When you click cursor up/down you change the highlighted selection within the dropdown but only when you hit return you actually change the value of the ComboBox. JavaFx just messed it to implement the UX that every user would expect here. This is a demo of a ComboBox with UX: http://www.jeasyui.com/demo/main/index.php?plugin=ComboBox – Jörg Oct 14 '20 at 21:17
  • BTW: I tried ChoiceBox and is nothing but a plain drop-down but without proper keyboard/filtering support. – Jörg Oct 14 '20 at 21:22

0 Answers0