Java 在控制器中使用.class筛选ObservableList项

Java 在控制器中使用.class筛选ObservableList项,java,javafx,javafx-8,Java,Javafx,Javafx 8,我正在尝试过滤ObservableList项,以便根据x规则在TableView中仅显示其中的一些项。为此,我有一个Database.class,其中有过滤数据的方法,但我不知道如何在控制器类中使用这些方法 这是上课时间 package es.upv.inf; import java.util.List; import java.util.Map; public class Database { private static Map<Product.Category, Lis

我正在尝试过滤ObservableList项,以便根据x规则在TableView中仅显示其中的一些项。为此,我有一个Database.class,其中有过滤数据的方法,但我不知道如何在控制器类中使用这些方法

这是上课时间

package es.upv.inf;

import java.util.List;
import java.util.Map;

public class Database {

    private static Map<Product.Category, List<Product>> catalog;

    public Database() {
        //Compiled Code
    }

    public static List<Product> getProductByCategory(Product.Category cat) {
        //Compiled Code
    }

    public static List<Product> getProductByCategoryAndPrice(Product.Category cat, double minPrice, double maxPrice, boolean available) {
        //Compiled Code
    }

    public static List<Product> getProductByCategoryAndDescription(Product.Category cat, String substring, boolean available) {
        //Compiled Code
    }

    public static List<Product> getProductByCategoryDescriptionAndPrice(Product.Category cat, String substring, double minPrice, double maxPrice, boolean available) {
        //Compiled Code
    }
}
包es.upv.inf;
导入java.util.List;
导入java.util.Map;
公共类数据库{
私有静态地图目录;
公共数据库(){
//编译代码
}
公共静态列表getProductByCategory(Product.Category目录){
//编译代码
}
公共静态列表getProductByCategoryAndPrice(Product.Category目录,双最小价格,双最大价格,布尔值可用){
//编译代码
}
公共静态列表getProductByCategoryAndDescription(Product.Category cat,字符串子字符串,布尔值可用){
//编译代码
}
公共静态列表GetProductByCategoryDescription和Price(Product.Category cat、字符串子字符串、双minPrice、双maxPrice、布尔值可用){
//编译代码
}
}

只需在可观察列表中使用
setAll
。您没有提供任何代码,但可以调用如下方法

TableView<Product> table = new TableView<>();

// ...

table.getItems().setAll(Database.getProductByCategory(...));
TableView table=newtableview();
// ...
table.getItems().setAll(Database.getProductByCategory(…);

使用Obseravble列表创建FilteredList,并通过setItems()将FilteredList安装到TableView中。然后可以操作FilteredList的谓词属性,表内容将发生更改。

将ObservableList转换为List。为什么?这已经是一个
列表
请更清楚地说明您想要实现的目标。这还不足以让我理解发生了什么。@YassinHajaj问题现在已经明确了?您的数据库类并没有真正过滤数据;它提供了它。筛选数据的方法将列表作为参数。