我第一次尝试测试SwingX,为此,我阅读了文档:http://www.jdocs.com/swingx/1.0/org/jdesktop/swingx/autocomplete/AutoCompleteDecorator.html
我想对这样的JTextField提出一个建议:
List items = [...];
JTextField textField = [...];
AutoCompleteDecorator.decorate(textField, items); 所以我在netbeans上创建了一个项目,这是我的代码:
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");
}
}

我得到了这个错误:
no suitable methode found for decorate....我很好地遵循了语法,我不明白错误是从哪里来的?有什么帮助吗?
发布于 2012-02-07 14:55:32
您的方法修饰调用,被解析为下面的第一个方法,该方法是不正确的。第二个方法装饰预期的JList而不是list。
public static void decorate(JComboBox comboBox, ObjectToStringConverter stringConverter)
public static void decorate(JList list, JTextComponent textComponent) 但是,如果您仍然希望使用List,则应该使用此方法,
public static void decorate(JTextComponent textComponent, List<?> items, boolean strictMatching)我已经用这个修改了你问题中的错误部分。
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);
}
}https://stackoverflow.com/questions/9169859
复制相似问题