2012-02-07 80 views
1

我试图测试SwingX首次,对于这一点,我读的文档:http://www.jdocs.com/swingx/1.0/org/jdesktop/swingx/autocomplete/AutoCompleteDecorator.htmlSwingX AutoCompleteDecorator:没有合适的梅索德发现装饰

我想做出一个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"); 

} 
} 

enter image description here

我得到这个错误:

no suitable methode found for decorate.... 

我下面还有语法,我不明白的地方的错误来? 任何帮助?

+0

请学习Java命名约定并严格遵守 – kleopatra 2012-02-07 16:50:33

+0

感谢您的建议.. – 2012-02-07 17:07:53

回答

1

你的方法装饰调用,是解决以下第一种方法是不正确的。第二种方法装饰预期的JList而不是列表。

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

但是,如果您仍想使用列表,你应该使用这种方法,

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); 
    } 

} 
+0

是它工作得很好,这场灾难是有在doc错误:o ...看到:HTTP:// www.jdocs.com/swingx/1.0/org/jdesktop/swingx/1.0/org/jdesktop/swingx/autocomplete/AutoCompleteDecorator.html – 2012-02-07 16:55:07

+1

呵呵,好吧,如果文档有混淆,只需阅读源代码本身,应该始终工作。顺便说一句,我使用的是swingx版本1.6.2 – Jasonw 2012-02-07 17:10:28