2017-11-29 17 views
-2

javafxのテーブルビューにデータを表示するプロジェクトがあります。問題は:エントリに1つのデータがある場合、それはtableviewに表示できます。しかし、私はリストに複数のデータを追加したいですが、私はどのようにわかりません。どこで編集すればよいですか?テーブルビューにJavafxはテーブルビューに複数のデータを挿入できません

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); 

} 

挿入データを:

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); 


} 
+0

「エラーが発生します。何のエラー? –

+0

@ James_D私はtableviewに複数のエントリを表示することはできませんが、listviewに1つのエントリを持つtableviewに表示できます。 – JhihweiLi

+0

申し訳ありません@James_Dエラーはありません。私はテーブルビューに複数のデータを挿入する方法を知りません。 – JhihweiLi

答えて

0

これらの線の多くはループ

private void showDataInTable(OrderedList entryList){ 
    ObservableList<Entry> list = FXCollections.emptyObservableList(); 
    for(int i=0;i<entryList.size();i++){ 
     Entry entry=entryList.get(i); 
     list.add(entry); 
    } 

    Col_Journal.setCellValueFactory(new PropertyValueFactory<Entry, String>("journal")); 
    Col_Booktitle.setCellValueFactory(new PropertyValueFactory<Entry, String>("booktitle")); 
    Col_Author.setCellValueFactory(new PropertyValueFactory<Entry, String>("author_str")); 
    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")); 

    table_id.setItems(list); 

} 

外に滞在することになっている私はcheckFieldを削除した、あなたはその多くが同様の必要はありません。クラスの場合は、このような外観の大きなEntryクラスを使用し、未使用のフィールドを空白のままにしておくことができます。

public class Entry { 

    private SimpleStringProperty journal = new SimpleStringProperty(""); 
    private SimpleStringProperty booktitle = new SimpleStringProperty(""); 
    private SimpleStringProperty author_str = new SimpleStringProperty(""); 
    private SimpleStringProperty editor = new SimpleStringProperty(""); 
    private SimpleStringProperty name = new SimpleStringProperty(""); 
    private SimpleStringProperty title = new SimpleStringProperty(""); 
    private SimpleStringProperty year = new SimpleStringProperty(""); 
    private SimpleStringProperty entryType = new SimpleStringProperty(""); 

    public Entry(String Sjournal, String Sbooktitle, String Sauthor_str, String Seditor, String Sname, String Stitle, String Syear, String SentryType){ 
     journal.set(Sjournal); 
     booktitle.set(Sbooktitle); 
     author_str.set(Sauthor_str); 
     editor.set(Seditor); 
     name.set(Sname); 
     title.set(Stitle); 
     year.set(Syear); 
     entryType.set(SentryType); 
    } 

} 
関連する問題