Javafx如何将数据插入tableview

时间:2017-11-27 13:19:28

标签: javafx insert tableview scenebuilder

我对javafx有疑问。我有一个使用bib文件操作的项目。我想在表视图中插入类数据(Entry)时遇到问题。但是在tableview中它仍然是空的。该操作是键入名称并从bib文件中搜索,然后在表视图中显示结果。 谢谢 The gui image

我有一个班级

public class Entry implements Comparable<Entry>{
  public static final int ignoreOrder=-1;
  public static final int OrderByName=0;
  public static final int OrderByTitle=1;
  public static final int OrderByYear=2;
  private String name;
  private String title="";
  private String year="0";
  private int order=OrderByName;

  public int getOrder() {
      return order;
  }
  public void setOrder(int order) {
      this.order = order;
  }
  public Entry(String name){
      this.name=name;
  }
  public String getName() {
      return name;
  }

  public void setName(String name) {
      this.name = name;
  }

  public String getTitle() {
      return title;
  }
  public void setTitle(String title) {

      this.title = title;
  }
  public String getYear() {
      return year;
  }
  public void setYear(String year) {
      this.year = year;
  }
}

填写tableview,但它仍然是空的。

@FXML
private TableView<Entry> table_id;
@FXML
private TableColumn<Entry, String> Col_BKey;
@FXML
private TableColumn<Entry, String> Col_counts;
@FXML
private TableColumn<Entry, String> Col_EntryType;
@FXML
private TableColumn<Entry, String> Col_Title;
@FXML
private TableColumn<Entry, String> Col_Year;
@FXML
private TableColumn<Entry, String> Col_Booktitle;
@FXML
private TableColumn<Entry, String> Col_Author;




public void loadFile(ActionEvent event){
        int orderModel=0;
        if(title_radio.isSelected()){
            orderModel=1;
        }else if(year_radio.isSelected()){
            orderModel=2;
        }
        ReadingProcessor readingProcessor=new ReadingProcessor(new OrderedLinkedList(orderModel));
        entryList=readingProcessor.read(filePath);
    }

    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!");
        }

        ObservableList<Entry> list = FXCollections.observableArrayList(entry);
        table_id.setItems(list);

    }

0 个答案:

没有答案