SwingX AutoCompleteDecorator:找不到合适的装饰方法

发布于 2025-01-03 06:13:07 字数 1642 浏览 1 评论 0原文

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

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

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄意 2025-01-10 06:13:07

您的方法装饰调用将解析为下面的第一个方法,该方法是不正确的。第二种方法装饰预期的 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);
    }

}

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文