SwingX AutoCompleteDecorator : no suitable methode found for decorate
Asked Answered
C

1

1

I am trying to test SwingX for the first time,For this, I read the doc : http://www.jdocs.com/swingx/1.0/org/jdesktop/swingx/autocomplete/AutoCompleteDecorator.html

I'd like to make a suggestion on a JTextField like this:

List items = [...];

JTextField textField = [...];

AutoCompleteDecorator.decorate(textField, items); 

so I create a project on netbeans, this is my code:

package test_swingx;

import java.awt.Dimension;
import java.awt.HeadlessException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
*
* @author marwen
*/
public class Test_swingx extends JFrame {

public Test_swingx(String title) throws HeadlessException {

    this.setTitle(title);
    JPanel pan=new JPanel();
    JTextField jtf=new JTextField();
    jtf.setColumns(20);
    List items  = new ArrayList();
    items.add("hello");
    items.add("marwen");
    items.add("allooo");
    AutoCompleteDecorator.decorate(jtf, items);
    pan.add(jtf);
    this.setContentPane(pan);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
    this.setBounds(280, 150, 500, 200);

 }


 public static void main(String[] args) {

    Test_swingx tsx=new Test_swingx("helloo swingx");

 }
}

enter image description here

I get this error :

no suitable methode found for decorate....

I'm following well the syntax , I do not understand where the error come? ANY HELPS ?

Centennial answered 7/2, 2012 at 1:30 Comment(1)
please learn java naming conventions and stick to themInhalator
T
1

Your method decorate call, is resolve to the first method below which is incorrect. Second method decorate expected JList instead of list.

public static void decorate(JComboBox comboBox, ObjectToStringConverter stringConverter)
public static void decorate(JList list, JTextComponent textComponent) 

However, if you still want to use List, you should use this method,

public static void decorate(JTextComponent textComponent, List<?> items, boolean strictMatching)

I've changed the error part in your question with this.

import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

public class Test_swingx extends JFrame
{

    public Test_swingx(String p_title)
    {
        this.setTitle(p_title);
        JPanel pan = new JPanel();
        JTextComponent jtf = new JTextField();
        ((JTextField) jtf).setColumns(20);
        List items = new ArrayList();
        items.add("hello");
        items.add("marwen");
        items.add("allooo");
        AutoCompleteDecorator.decorate(jtf, items, false);
        pan.add(jtf);
        this.setContentPane(pan);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setBounds(280, 150, 500, 200);     
    }

    public static void main(String[] args)
    {
        Test_swingx tsx = new Test_swingx("helloo swingx");     
        tsx.setVisible(true);
    }

}
Trilley answered 7/2, 2012 at 6:55 Comment(2)
yes it works very well, the disaster is that there is an error in the doc :O... see : jdocs.com/swingx/1.0/org/jdesktop/swingx/autocomplete/…Centennial
hehe well yeah, if the doc has confusion, just read the source code itself, that should always work. ;-) by the way, i'm using swingx version 1.6.2Trilley

© 2022 - 2024 — McMap. All rights reserved.