user3245747 user3245747 - 5 months ago 11
Java Question

double clicking in the JComboBox results in a strange error

I have a strange problem. I'm working on a long program and in that program I create a JComboBox the following way:

String[] s = {"aa", "bb", "cc"};
JComboBox try1 = new JComboBox(s);
try1.insertItemAt("", 0);
try1.setSelectedIndex(0);
AutoCompleteDecorator.decorate(try1);


When I run the program, if the user double clicks inside the text area of the combo box I get the following runtime error:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.text.PlainDocument cannot be cast to javax.swing.text.StyledDocument
at org.jdesktop.swingx.autocomplete.AutoCompleteDocument.getParagraphElement(AutoCompleteDocument.java:309)
at javax.swing.text.Utilities.getParagraphElement(Utilities.java:850)
at javax.swing.text.Utilities.getWordStart(Utilities.java:631)
at javax.swing.text.DefaultEditorKit$BeginWordAction.actionPerformed(DefaultEditorKit.java:1750)
at javax.swing.text.DefaultEditorKit$SelectWordAction.actionPerformed(DefaultEditorKit.java:2163)
at javax.swing.text.DefaultCaret.selectWord(DefaultCaret.java:390)
at javax.swing.text.DefaultCaret.mousePressed(DefaultCaret.java:495)
at com.apple.laf.AquaCaret.mousePressed(AquaCaret.java:140)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:280)
at java.awt.Component.processMouseEvent(Component.java:6502)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.text.PlainDocument cannot be cast to javax.swing.text.StyledDocument
at org.jdesktop.swingx.autocomplete.AutoCompleteDocument.getParagraphElement(AutoCompleteDocument.java:309)
at javax.swing.text.Utilities.getParagraphElement(Utilities.java:850)
at javax.swing.text.Utilities.getWordStart(Utilities.java:631)
at javax.swing.text.DefaultEditorKit$BeginWordAction.actionPerformed(DefaultEditorKit.java:1750)
at javax.swing.text.DefaultEditorKit$SelectWordAction.actionPerformed(DefaultEditorKit.java:2163)
at javax.swing.text.DefaultCaret.selectWord(DefaultCaret.java:390)
at javax.swing.text.DefaultCaret.mouseClicked(DefaultCaret.java:415)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6508)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4501)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)


However, if I create a very simple program that contains nothing but the same JComboBox I do not have the same problem. I find this very strange because the JComboBox is not being used anywhere so far in my program. Can someone please tell me what might be causing this behaviour. Thanks.

Answer

Solution:

The problem was caused by the AutoCompleteDecorator. I deactivated it and used instead the AutoCompletion.enable(employeeDelete). I appreciate all the comments that helped me.

Comments