【问题标题】:SwingX AutoCompleteDecorator : no suitable methode found for decorateSwingX AutoCompleteDecorator:没有找到合适的装饰方法
【发布时间】:2012-02-28 12:04:49
【问题描述】:

我第一次尝试测试 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....

我很好地遵循了语法,我不明白错误来自哪里? 有什么帮助吗?

【问题讨论】:

  • 请学习java命名约定并遵守它们

标签: java swingx


【解决方案1】:

您的方法装饰调用,被解析为下面不正确的第一个方法。第二种方法装饰预期的 JList 而不是列表。

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

}

【讨论】:

  • 是的,它工作得很好,灾难是文档中有一个错误:O...请参阅:jdocs.com/swingx/1.0/org/jdesktop/swingx/autocomplete/…
  • 呵呵,好吧,如果文档有混淆,请阅读源代码本身,这应该总是有效的。 ;-) 顺便说一句,我使用的是 swingx 1.6.2 版
猜你喜欢
  • 2013-07-31
  • 2014-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-30
  • 2014-08-27
  • 2021-06-19
  • 2015-11-26
相关资源
最近更新 更多