Skip to main content

Autocomplete for JCombobox is broken

4 replies [Last post]
vity01
Offline
Joined: 2006-03-25

I can confirm, that SwingX autocomplete for JComboBox is broken.
Testcase

<br />
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;</p>
<p>import javax.swing.*;<br />
import java.awt.*;</p>
<p>/**<br />
 * @author Vity<br />
 * */<br />
public class BugTest {<br />
    public static void main(String[] args) {<br />
        SwingUtilities.invokeLater(new Runnable() {<br />
            public void run() {<br />
                show();<br />
            }<br />
        });<br />
    }</p>
<p>    private static void show() {<br />
        final JFrame test = new JFrame("Test");<br />
        test.getContentPane().add(getCombobox());<br />
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
        test.setLocationRelativeTo(null);<br />
        test.setSize(100, 50);<br />
        test.setVisible(true);<br />
    }</p>
<p>    private static Component getCombobox() {<br />
        final JComboBox jComboBox = new JComboBox();<br />
        AutoCompleteDecorator.decorate(jComboBox);<br />
        return jComboBox;<br />
    }<br />
}<br />

Exception:
<br />
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.text.PlainDocument cannot be cast to javax.swing.text.StyledDocument<br />
	at org.jdesktop.swingx.autocomplete.AutoCompleteDocument.getParagraphElement(AutoCompleteDocument.java:309)<br />
	at javax.swing.text.Utilities.getParagraphElement(Utilities.java:805)<br />
	at javax.swing.text.Utilities.getWordStart(Utilities.java:586)<br />
	at javax.swing.text.DefaultEditorKit$BeginWordAction.actionPerformed(DefaultEditorKit.java:1727)<br />
	at javax.swing.text.DefaultEditorKit$SelectWordAction.actionPerformed(DefaultEditorKit.java:2140)<br />
	at javax.swing.text.DefaultCaret.selectWord(DefaultCaret.java:373)<br />
	at javax.swing.text.DefaultCaret.mousePressed(DefaultCaret.java:478)<br />
	at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)<br />
	at java.awt.Component.processMouseEvent(Component.java:6091)<br />
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)<br />
	at java.awt.Component.processEvent(Component.java:5859)<br />
	at java.awt.Container.processEvent(Container.java:2058)<br />
	at java.awt.Component.dispatchEventImpl(Component.java:4466)<br />
	at java.awt.Container.dispatchEventImpl(Container.java:2116)<br />
	at java.awt.Component.dispatchEvent(Component.java:4296)<br />
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)<br />
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3983)<br />
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)<br />
	at java.awt.Container.dispatchEventImpl(Container.java:2102)<br />
	at java.awt.Window.dispatchEventImpl(Window.java:2454)<br />
	at java.awt.Component.dispatchEvent(Component.java:4296)<br />
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)<br />
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:284)<br />
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)<br />
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)<br />
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)<br />
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)<br />
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)<br />

How to reproduce
I tested it on the latest build (24th August). Just double click in editor or use eg. ctrl+backspace.
I guess that the fix will be easy. It just counts only with JEditorPane or something.

Shall I add it to the IssueTracker?

Message was edited by: vity01

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vinh_truong
Offline
Joined: 2005-12-22

I found this on the net. Hope that it may help to fix problem in AutoCompleteDecorator class or someone working on JXComboBox.

http://www.java.happycodings.com/Java_Swing/code5.html

vinh_truong
Offline
Joined: 2005-12-22
kschaefe
Offline
Joined: 2006-06-08

Please file an issue.

Karl

vity01
Offline
Joined: 2006-03-25