我在我的项目中添加了自动完成的元素;但在用户输入一个单词后,自动完成算法停止。我可以添加更多字符,但是没有自动完成的建议。
我正在使用JSuggestField
(将 jar 添加到我的项目中),这里是说明问题的SSCCE :
import javax.swing.*;
import ch.rakudave.suggest.JSuggestField;
import java.awt.*;
import java.util.Vector;
public class Classic extends JFrame {
public static final String CHILD = "/child::";
public static final String DESCENDANT = "/descendant::";
public static final String FOLLOWING_SIBLING = "/following-sibling::";
public static final String DESCENDANT_OR_SELF = "/descendant-or-self::";
public static final String SELF = "/self::";
public static final String PRECEDING_SIBLING = "/preceding-sibling::";
public static final String ANCESTOR_OR_SELF = "/ancestor-or-self::";
public static final String ANCESTOR = "/ancestor::";
public static final String FOLLOWING = "/following::";
public static final String PRECEDING = "/preceding::";
public Classic() {
initComponents();
}
private void initComponents() {
Vector<String> vector = new Vector<String>();
vector.add(DESCENDANT);
vector.add(FOLLOWING_SIBLING);
vector.add(DESCENDANT_OR_SELF);
vector.add(SELF);
vector.add(PRECEDING_SIBLING);
vector.add(ANCESTOR_OR_SELF);
vector.add(ANCESTOR);
vector.add(FOLLOWING);
vector.add(PRECEDING);
JSuggestField jsuggest= new JSuggestField(this,vector );
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200, 200);
Container container = getContentPane();
container.setLayout(new FlowLayout(FlowLayout.LEFT));
JTextField textField = new JTextField(15);
jsuggest.setPreferredSize(new Dimension(100, 20));
//
// Right justify the JTextField contents
//
jsuggest.setHorizontalAlignment(JTextField.RIGHT);
container.add(jsuggest);
textField = jsuggest;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Classic().setVisible(true);
}
});
}
}
这是一个快照:。
这很好,但我希望每次用户输入字符后自动完成功能都会起作用/
,因此一个自动完成功能是不够的。
知道如何使用JSuggestField
或其他方法解决此问题吗?
谢谢。