我有一个需要在javafx的tableview上显示数据的项目。问题是:如果条目中有一个数据,它可以在tableview上显示。但我想添加多个数据列表,但我不知道如何。我应该在哪里编辑?
public void SelectOKAction(ActionEvent event) {
String searchStr=select_text.getText();
if(searchStr==null||searchStr.trim().equals("")){
AlertBox.display("Wrong", "Please enter entry's name");
return;
}
Entry entry=entryList.search(searchStr);
if(entry==null){//NOT FOOUND
AlertBox.display("Wrong", "Entry not exists!");
}
//show data in table
OrderedList l=new OrderedLinkedList();
l.add(entry);
showDataInTable(l);
}
将数据插入tableview:
private void showDataInTable(OrderedList entryList){
ObservableList<Entry> list = FXCollections.emptyObservableList();
for(int i=0;i<entryList.size();i++){
Entry entry=entryList.get(i);
Class<? extends Entry> clz=entry.getClass();
if(Untils.checkField(clz, "journal")){
Col_Journal.setCellValueFactory(new PropertyValueFactory<Entry, String>("journal"));
}
if(Untils.checkField(clz, "booktitle")){
Col_Booktitle.setCellValueFactory(new PropertyValueFactory<Entry, String>("booktitle"));
}
if(Untils.checkField(clz, "author")){
Col_Author.setCellValueFactory(new PropertyValueFactory<Entry, String>("author_str"));
}
if(Untils.checkField(clz, "editor")){
Col_Editor.setCellValueFactory(new PropertyValueFactory<Entry, String>("editor"));
}
Col_BKey.setCellValueFactory(new PropertyValueFactory<Entry, String>("name"));
Col_Title.setCellValueFactory(new PropertyValueFactory<Entry, String>("title"));
Col_Year.setCellValueFactory(new PropertyValueFactory<Entry, String>("year"));
Col_EntryType.setCellValueFactory(new PropertyValueFactory<Entry, String>("entryType"));
list.add(entry);
}
table_id.setItems(list);
}