The ComboBoxListViewSkin class implementation fails within my ComboBoxAutoComplete class constructor when it has to be reinitialized because of updated ComboBox database data. The ComboBoxListViewSkin class is only being used to allow the user to enter a [SPACE] in the auto-completion search through the skin. This also prevents the [SPACE] from selecting and closing the ComboBox List (expected and wanted). It's a nice feature. This functionality works great when the application is first opened with the user default database, but if that database is updated or a new database opened, it requires this ComboBox to be updated and the AutoCompletion reinitialized.
This is a custom AutoCompletion class because this is being performed on 'uneditable' ComboBoxes (combobox.setEditable(false)). ControlsFX does not have this ability except on "editable" ComboBoxes.
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
The code within the constructor:
The cbSkin could probably be a local variable. I declared it private outside the constructor because it seemed to impact whether the 'carrot' in the upper left corner of the ComboBox was visible or not.
What is expected:
The capability of the ComboBox to retain original initialized functionality when updating or switching between databases, which allow the ability to use a [SPACE-KEY] when searching on topics in a ComboBox.
What I have tried:
I've tried using various if statements either prior to, or wrapped around this functionality in the constructor in an attempt to reinitialize it, or to simply remove and apply a new skin (cmb.setSkin()). But nothing seems to work. I have thought about and tried initializing the ComboBoxListViewSkin outside the ComboBoxAutoCompletion class, but I don't think that is possible. When I pass the ComboBox to the class, I don't see a way of setting up the getPopupContent().addEventFilter from the ComboBox being passed. I tried through the cmb.getSkin(), but with no success. Secondly, the getPopupContent().addEventFilter has the lamda calls referencing the encapsulated variable 'filter', which retains the characters and [SPACE] during the user interaction.
Lastly, I receive the 'carrot' in the upper left corner of the ComboBox (see image) when the second initialization is attempted; which I had before until I added "cmb.setSkin(cbSkin)" and it went away. However, this is back now. A minor issue, more aesthetic, but I'm hoping will disappear if I can figure out with some help how to solve this problem.
What I'm doing here isn't common on an uneditable ComboBox, and custom in that respect. Even though searched I didn't find anything except what I had posted as a resolution to this issue if you only needed a single instance on SuperUser/StackOverflow... and wanted to remove the 'carrot'.
I solved my issue and the solution was stupidly obvious. I simply only needed to initialize my ComboBoxAutoCompletion once and just pass the updated list for each update or databaase change. To demonstrate I used a boolean to track the first initialization. For some odd reason the caret is appearing in the upper left corner of the box now. Previously, adding the "this.cmb.setSkin(cbSkin)" caused this to disappear. I consider this issue post solved since core functionality works.
Minor constructor update with public ObservableList for updating: