如何在Java中过滤TableView中的整数?

时间:2017-12-30 14:09:46

标签: java javafx

我正在尝试通过我称之为Log ID的Integer搜索表,并显示具有该Log ID的所有行。

我可以像这样轻松搜索字符串

@FXML void searchNameLogs(){
    String searchText = searchNameField.getText();
    FilteredList<AddLogs> searchLogResults = searchNameLogs(searchText);
    SortedList<AddLogs> sortedData = new SortedList<>(searchLogResults);


    sortedData.comparatorProperty().bind(logsTableView.comparatorProperty());
    logsTableView.setItems(sortedData);
    searchNameField.setText("");
} 

public FilteredList<AddLogs> searchNameLogs(String s){
    return LogsView.getLogView().filtered(p -> 
    p.getName().toLowerCase().contains(s.toLowerCase()));      
}

我可以使用这样的东西来搜索整数吗?

我也尝试了别的东西。

在我的主屏幕控制器中,我添加了

@FXML void searchLogId(ActionEvent event) throws IOException {
    String searchLog = searchLogIdField.getText();
    String searchLogParts = searchLogIdField.getText();

    int logIndex = -1;
    int logIndex2 = -1;

    logIndex = LogsView.searchLog(searchLog);
    logIndex2 = PartsLogsView.searchPartLogId(searchLogParts);

    AddLogs tempLog = LogsView.getLogView().get(logIndex);
    AddPartsLog tempLog2 = PartsLogsView.getPartsLogView().get(logIndex2);

    ObservableList<AddLogs> tempLogList = FXCollections.observableArrayList();
    ObservableList<AddPartsLog> tempLogList2 = FXCollections.observableArrayList();

    tempLogList.add(tempLog);
    tempLogList2.add(tempLog2);

    logsTableView.setItems(tempLogList);  
    partsUsedTableView.setItems(tempLogList2);      

    searchLogIdField.setText("");
}

在另一堂课中我有:

public static int searchPartLogId(String searchTerm) {
    boolean isFound = false;
    int index = 0;
    if (isInteger(searchTerm)) {
        for (int i = 0; i < partsLog.size(); i++) {
            if (Integer.parseInt(searchTerm) == partsLog.get(i).getPartsLogId()) {
                index = i;
                isFound = true;
                System.out.println(partsLog.get(i).getPartsLogId());
            }
        }
    }
    if (isFound = true) {
        return index;
    } else {
        System.out.println("No part log found.");
        return -1;
    }
}

public static boolean isInteger(String input) {
    try {
        Integer.parseInt(input);
        return true;
    } catch (Exception e) {
        return false;
    }
}

问题在于它只显示我搜索的Log ID的第一次出现的行。如果我有12个具有相同日志ID的部分,我需要在表中包含所有12个部分。

0 个答案:

没有答案