Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何禁用JavaFX组合框中的箭头按钮_Javafx - Fatal编程技术网

如何禁用JavaFX组合框中的箭头按钮

如何禁用JavaFX组合框中的箭头按钮,javafx,Javafx,我有一个我正在做的项目。我正在努力编一本字典。为此,我有一个约55000个单词的.csv文件。我正在使用trie数据结构,它有一个startsWith()方法,用于检查.csv文件中是否有与给定前缀匹配的单词。我设法让它工作起来,找到与给定前缀匹配的所有单词并显示它们。现在,我必须把它开发成一个JavaFX应用程序 因此,我考虑使用一个组合框,它的可编辑属性设置为true,这样我就可以在其中键入内容,然后与它的编辑器的textProperty()关联的处理程序将在组合框的列表视图中显示所有以给定

我有一个我正在做的项目。我正在努力编一本字典。为此,我有一个约55000个单词的
.csv
文件。我正在使用
trie
数据结构,它有一个
startsWith()
方法,用于检查
.csv
文件中是否有与给定前缀匹配的单词。我设法让它工作起来,找到与给定前缀匹配的所有单词并显示它们。现在,我必须把它开发成一个JavaFX应用程序

因此,我考虑使用一个
组合框
,它的可编辑属性设置为true,这样我就可以在其中键入内容,然后与它的
编辑器
textProperty()
关联的处理程序将在组合框的
列表视图
中显示所有以给定前缀开头的单词

现在,我遇到的问题是,每当我单击组合框的箭头按钮时,应用程序就会停止响应(我认为这是因为列表视图试图调整自身大小以适应55000个项目)。 所以,我想知道的是如何完全禁用箭头按钮。我曾尝试将其
背景色设置为透明,但即使如此,仍可以单击它。我希望将其设置为禁用和透明。基本上,组合框最终看起来像一个文本字段


如果有更好、更有效的实现词典的方法,如果您能指导我,我将不胜感激。

ListView是一个虚拟控件,一次只显示一定数量的单元格,它不需要以任何方式“根据项目数调整大小”,从而锁定GUI

这个演示程序是否符合您的要求

public class Main extends Application {

    public static void main(String[] args) throws IOException, URISyntaxException {
        launch(args);
    }


    @Override
    public void start(Stage stage) {
        List<String> rawWords = Collections.emptyList();
        try {
            URI wordURI = new URI("https://www-cs-faculty.stanford.edu/~knuth/sgb-words.txt");
            BufferedReader reader = new BufferedReader(new InputStreamReader(wordURI.toURL().openStream(), StandardCharsets.UTF_8));
            rawWords = reader.lines().collect(Collectors.toCollection(() -> new ArrayList<>(6000)));
        } catch (IOException | URISyntaxException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

        // make the list at least as big as in the question
        while(rawWords.size() < 55000) {
            ArrayList<String> nextWords = new ArrayList<>(rawWords.size() * 2);
            nextWords.addAll(rawWords);
            nextWords.addAll(rawWords);
            rawWords = nextWords;
        }

        Collections.sort(rawWords);
        ObservableList<String> wordList = FXCollections.observableArrayList(rawWords);
        FilteredList<String> filteredList = new FilteredList<>(wordList);
        ComboBox<String> combo = new ComboBox<>(filteredList);
        combo.setEditable(true);
        combo.getEditor().textProperty().addListener((obs, oldVal, newVal) -> {
            filteredList.setPredicate(s -> newVal == null || newVal.isEmpty() || s.startsWith(newVal));
        });
        VBox vbox = new VBox(8,new Label("Dictionary ComboBox"),
                combo,
                new Label("\n\n\n\nThis space intentionally left blank.\n\n\n\n"));
        vbox.setPadding(new Insets(8));
        Scene scene = new Scene(vbox, 400, 300);
        stage.setTitle("Demo - Filtered Combobox List");
        stage.setScene(scene);
        stage.show();
    }
}
public类主扩展应用程序{
publicstaticvoidmain(字符串[]args)抛出IOException、URISyntaxException{
发射(args);
}
@凌驾
公众假期开始(阶段){
List rawWords=Collections.emptyList();
试一试{
URI wordURI=新URI(“https://www-cs-faculty.stanford.edu/~knuth/sgb words.txt);
BufferedReader=新的BufferedReader(新的InputStreamReader(wordURI.toURL().openStream(),StandardCharsets.UTF_8));
rawWords=reader.lines().collect(collector.toCollection(()->newarraylist(6000));
}catch(IOException | URISyntaxException ex){
Logger.getLogger(Main.class.getName()).log(Level.SEVERE,null,ex);
}
//让清单至少和问题中的一样大
while(rawWords.size()<55000){
ArrayList nextWords=新的ArrayList(rawWords.size()*2);
nextWords.addAll(rawWords);
nextWords.addAll(rawWords);
rawWords=nextWords;
}
集合。排序(rawWords);
ObservableList wordList=FXCollections.observableArrayList(rawWords);
FilteredList FilteredList=新的FilteredList(单词列表);
组合框组合=新组合框(filteredList);
combo.setEditable(真);
combo.getEditor().textProperty().addListener((obs,oldVal,newVal)->{
setPredicate(s->newVal==null | | | newVal.isEmpty()| | s.startsWith(newVal));
});
VBox VBox=新VBox(8,新标签(“字典组合框”),
联合体,
新标签(“\n\n\n\n此空格故意留空。\n\n\n\n”);
vbox.setPadding(新插图(8));
场景=新场景(vbox,400300);
stage.setTitle(“演示-过滤组合框列表”);
舞台场景;
stage.show();
}
}

为什么不使用
文本字段
?在中筛选列表onShowing@Sedrick这将如何允许用户从所有匹配前缀的单词中选择一个单词,就像您需要一个自动完成的
TextField
@Sedrick我该如何向用户显示与文本字段中写入的前缀匹配的单词?它确实有过滤单词的功能,但我想删除箭头按钮,因为如果组合框必须存储55000个单词,并且单击箭头按钮,程序将停止响应,因此我想找到一种删除按钮的方法,以便解决了那个问题,我无法重现那个问题。我修改了上述程序,以确保列表中至少有55000个单词。单击箭头时出现了轻微的停顿,但就是这样。如果您不希望用户能够激活选项列表,那么使用组合框的意义也不清楚。我希望用户在组合框中键入前缀,当键入的前缀与字典中存在的任何单词的前缀匹配时,将显示匹配单词的弹出窗口,就像在自动完成文本字段中一样,但是问题是我被告知不要使用自动完成文本字段,而是用其他方式。这就是为什么我想禁用箭头按钮并使其透明,这样用户就不能单击它。我想要的正是这个答案所做的——为您拼写家庭作业;)忘了你解决这个问题的想法吧,这是个死胡同。。