I always get an error of my Auto Completing JComboBox. To auto complete my jcombobox i used this script of http://w_w.orbital-computer.de/JComboBox/. When I create them i do it like this:
final Object[] elements = new Object[] {"Please refresh your list"};
comboBox[i] = new JComboBox(elements);
comboBox[i].setEditable(true);
new AutoCompleteJComboBox(comboBox[i]);
It works fine if i just use it with new jcomboboxes, but if i change their values like this:
comboBox[i].removeAllItems();
comboBox[i].setModel(new JComboBox<>(ListWithNames).getModel());
comboBox[i].setEditable(true);
new AutoCompleteJComboBox(comboBox[i]);
I get the following error message:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: bad position: 11
at javax.swing.text.JTextComponent.setCaretPosition(Unknown Source)
at src.AutoCompleteJComboBox.highlightCompletedText(AutoCompleteJComboBox.java:146)
at src.AutoCompleteJComboBox.access(AutoCompleteJComboBox.java:145)
at src.AutoCompleteJComboBoxactionPerformed(AutoCompleteJComboBox.java:30)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopupprocessMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access(Unknown Source)
at java.awt.EventQueuerun(Unknown Source)
at java.awt.EventQueuerun(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomaindoIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomaindoIntersectionPrivilege(Unknown Source)
at java.awt.EventQueuerun(Unknown Source)
at java.awt.EventQueuerun(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomaindoIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
this position 11 is the length of the first value in the ListWithNames, additionally the first item in the list still works fin but by the other items is just the first letter of the text highlighted and than the error appears.
AutoCompleteJComboBox.java is this file with another name in line 146 is
editor.setCaretPosition(this.getLength());
I hope someone can help me with this.
(sorry for that link at the top, but im not allowed to post more than two)