I have an AutoCompleteTextField working with a DefaultListModel.
options = new DefaultListModel<>();
labelACField = new AutoCompleteTextField(options){
@Override
protected boolean filter(String text) {
}
};
The return value from options.getSelectedIndex() always returns 0 from actionPerformed, even users choose other items in the AutoCompleteTextField.
labelACField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (filteredIdObjs!=null){
selectedIdx = options.getSelectedIndex();
For example, a user clicks "VV Vanguard Large-Cap ETF" or IVOV....or IVVD, or CVV.. the return value from options.getSelectedIndex() always returns 0.
How do I get the item index that the user clicks?
That's an interface designed for a List. AutoCompleteTextField
uses the ListModel
interface for ease of use. But it doesn't use selection since it's inherently a text field.
The output is the text within the text field. Not list selection since a user can type in any arbitrary value without selecting a value from the list.