Adapt jComboBox Code with Autocomplete

Asked

Viewed 185 times

0

Option 1: How can I adapt this code to my project? I created the Autocompletation class and then put it in my constructor:

AutoCompletion.enable(yourComboBox);

I dragged my combobox in the design part and defined it as 'Editable'. When I run my project, when I write anything on my combobox gives me this mistake:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at _global.AutoCompletion.insertString(AutoCompletion.java:141)
    at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:669)
    at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1328)
    at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:884)
    at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1663)
    at javax.swing.JComponent.processKeyBinding(JComponent.java:2879)
    at javax.swing.JComponent.processKeyBindings(JComponent.java:2926)
    at javax.swing.JComponent.processKeyEvent(JComponent.java:2842)
    at java.awt.Component.processEvent(Component.java:6302)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771)
    at java.awt.Component.dispatchEventImpl(Component.java:4752)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Window.dispatchEventImpl(Window.java:2739)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:719)
    at java.awt.EventQueue$4.run(EventQueue.java:717)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Does anyone have any idea where I might be missing?

Option 2:

Maybe I should go for this solution : Autocomplete Jcombobox

I managed by functional, but I would like to apply this autocomplete to a checkbox of mine. How can I do this?

  • Apply autocomplete to a checkbox or combobox? Just copy the classes and put them in the same package as an application of yours (for example the class I put as an answer to your other question).

  • But I’ve imported the class I want to use, now how do I apply it to the object I want ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.