在Controller中使用.class过滤ObservableList项

时间:2016-03-27 11:59:30

标签: java javafx javafx-8

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

这是.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
    }
}

2 个答案:

答案 0 :(得分:0)

在可观察列表上使用setAll。您还没有提供任何代码,但您可以调用

等方法
TableView<Product> table = new TableView<>();

// ...

table.getItems().setAll(Database.getProductByCategory(...));

答案 1 :(得分:0)

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

相关问题