3

Auto Completing JComboBox のエラーが常に発生します。jcombobox をオートコンプリートするために、 http://w_w.orbital-computer.de/JComboBox/のスクリプトを使用しました。それらを作成するときは、次のようにします。

final Object[] elements = new Object[] {"Please refresh your list"};
comboBox[i] = new JComboBox(elements);
comboBox[i].setEditable(true);                                  
new AutoCompleteJComboBox(comboBox[i]);

新しいjcomboboxesで使用するだけで問題なく動作しますが、値を次のように変更すると:

comboBox[i].removeAllItems();    
comboBox[i].setModel(new JComboBox<>(ListWithNames).getModel());
comboBox[i].setEditable(true);
new AutoCompleteJComboBox(comboBox[i]);

次のエラー メッセージが表示されます。

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)

この位置 11 は、ListWithNames の最初の値の長さです。さらに、リストの最初の項目は正常に機能しますが、他の項目によって強調表示されたテキストの最初の文字にすぎず、エラーが表示されます。

AutoCompleteJComboBox.java は、 146 行目の別の名前のこのファイルです。

editor.setCaretPosition(this.getLength());

誰かがこれで私を助けてくれることを願っています。

(上部のリンクは申し訳ありませんが、2つ以上投稿することはできません)

4

0 に答える 0