0

我目前正在使用 ControlsFX 的 AutoComplete TextField 功能在用户键入时显示建议。建议的数量很大,因此该列表不适合页面。

我想将字符串列表的长度设置为最大值,但这在 ControlsFX 中尚不可能(据我所知)。因此,我正在考虑一种解决方法,其中列表仅在用户键入 3 个或更多字符的字符串时显示。

现在,我已将此操作设置为在单击 TextField 时执行(其中 searchCustomer 是我的 TextField):

@FXML
private void searchCustomer() {
    //Get all customers from shop
    String[][] customersOfShop = octocash.Main.databaseConnection.getData("some query", 
                    Arrays.asList("some columname"));

    //Convert 2D array to 1D array
    int noOfRows = customersOfShop.length;
    String[] customersForList = new String[noOfRows];
    for(int k=0; k<noOfRows; k++) {
        customersForList[k] = customersOfShop[k][0];
    }
    //Set values to AutoComplete TextField
    TextFields.bindAutoCompletion(searchCustomer, customersForList);
}

如何在 java/javaFX8 中执行此操作?

4

1 回答 1

1

一种方法可以是观察文本长度:

IntegerBinding ib = Bindings.length(textField.textProperty());

ib.addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
    if(newValue.intValue() >= 3) {
        // trigger auto complete
    }
});
于 2014-10-10T12:57:33.330 回答