我正在尝试按照某一列来排序
我希望首先按性别对表进行排序。
据我所知,我必须创建一个
我必须使用
这是我找到的链接之一:http://code.makery.ch/blog/javafx-8-tableview-sorting-filtering/ 请问有人能为我简单解释一下吗?
TableView表
。当我展示这个表格时,它确实被显示了出来,但是从这里和其他网站上所发现的内容来看,越看越让我感到困惑。
以下是TableView的代码:
public TableView<Animal> animalLostLocation(ArrayList<Animal> list)
{
TableColumn<Animal, String> atypeColumn = new TableColumn<>("Animal Type");
atypeColumn.setMinWidth(200);
atypeColumn.setSortable(false);
atypeColumn.setCellValueFactory(new PropertyValueFactory<>("aType"));
TableColumn<Animal, String> descriptionColumn = new TableColumn<>("Description");
descriptionColumn.setMinWidth(200);
descriptionColumn.setSortable(false);
descriptionColumn.setCellValueFactory(new PropertyValueFactory<>("description"));
TableColumn<Animal, String> breedColumn = new TableColumn<>("Breed");
breedColumn.setMinWidth(80);
breedColumn.setSortable(false);
breedColumn.setCellValueFactory(new PropertyValueFactory<>("breed"));
TableColumn<Animal, String> nameColumn = new TableColumn<>("Name");
nameColumn.setMinWidth(200);
nameColumn.setSortable(false);
nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
TableColumn<Animal, Catergory> catColumn = new TableColumn<>("Category");
catColumn.setMinWidth(200);
breedColumn.setSortable(false);
catColumn.setCellValueFactory(new PropertyValueFactory<>("category"));
TableColumn<Animal, Integer > ageColumn = new TableColumn<>("Age");
ageColumn.setMinWidth(50);
ageColumn.setSortable(false);
ageColumn.setCellValueFactory(new PropertyValueFactory<>("age"));
TableColumn<Animal, Integer > idColumn = new TableColumn<>("ID");
idColumn.setMinWidth(50);
idColumn.setCellValueFactory(new PropertyValueFactory<>("ID"));
TableColumn<Animal, Boolean > genColumn = new TableColumn<>("Male");
genColumn.setMinWidth(50);
genColumn.setSortable(false);
genColumn.setCellValueFactory(new PropertyValueFactory<>("gender"));
table = new TableView<Animal>();
table.setItems(getAnimal(list));
table.getColumns().addAll(genColumn, idColumn, nameColumn, atypeColumn, ageColumn, breedColumn, descriptionColumn, catColumn);
return table;
}
我希望首先按性别对表进行排序。
据我所知,我必须创建一个
SortedList
/ FilteredList
,但我在网上找到的教程更加令我困惑。我必须使用
SortedList
/ FilteredList
吗?还有更好的替代方案吗?这是我找到的链接之一:http://code.makery.ch/blog/javafx-8-tableview-sorting-filtering/ 请问有人能为我简单解释一下吗?
TableView
已经提供了排序功能这一事实,我倾向于同意他的看法...这个网站可能不是最好的学习资源...(虽然我还没有在这个网站上阅读足够的内容来做一个有根据的总体质量评价) - fabian