2017-02-01 13 views
0

私が間違っていることは得られません。すべてがOKだと思われますが、データはテーブルにロードされません。 これは、ステージのコントローラクラスである:JavaFXなぜTableViewにデータがロードされないのですか

package application.controllers; 

import application.meetings.MeetingData; 
import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import javafx.event.ActionEvent; 
import javafx.fxml.FXML; 
import javafx.scene.control.*; 
import javafx.scene.control.cell.PropertyValueFactory; 

import java.net.URL; 
import java.util.ResourceBundle; 

public class EditMeetingPopUpController { 

    @FXML // ResourceBundle that was given to the FXMLLoader 
    private ResourceBundle resources; 

    @FXML // URL location of the FXML file that was given to the FXMLLoader 
    private URL location; 

    @FXML // fx:id="dateAndTimeInformation" 
    private DatePicker dateAndTimeInformation; // Value injected by FXMLLoader 

    @FXML // fx:id="hoursInformation" 
    private ComboBox<String> hoursInformation; // Value injected by FXMLLoader 

    @FXML // fx:id="minutesInformation" 
    private ComboBox<String> minutesInformation; // Value injected by FXMLLoader 

    @FXML // fx:id="placeInformation" 
    private TextField placeInformation; // Value injected by FXMLLoader 

    @FXML // fx:id="categoryInformation" 
    private ComboBox<String> categoryInformation; // Value injected by FXMLLoader 

    @FXML // fx:id="contactsInformation" 
    private ComboBox<String> contactsInformation; // Value injected by FXMLLoader 

    @FXML // fx:id="allSelectedContactsTextArea" 
    private TextArea allSelectedContactsTextArea; // Value injected by FXMLLoader 

    @FXML // fx:id="commentInformation" 
    private TextArea commentInformation; // Value injected by FXMLLoader 




    // Table variables 

    @FXML // fx:id="meetingTable" 
    private TableView<MeetingData> meetingTable; // Value injected by FXMLLoader 

    @FXML // fx:id="dateAntTimeColumn" 
    private TableColumn<MeetingData, String> dateAntTimeColumn; // Value injected by FXMLLoader 

    @FXML // fx:id="placeColumn" 
    private TableColumn<MeetingData, String> placeColumn; // Value injected by FXMLLoader 

    @FXML // fx:id="categoryColumn" 
    private TableColumn<MeetingData, String> categoryColumn; // Value injected by FXMLLoader 

    @FXML // fx:id="contactsColumn" 
    private TableColumn<MeetingData, String> contactsColumn; // Value injected by FXMLLoader 

    @FXML // fx:id="commentsColumn" 
    private TableColumn<MeetingData, String> commentsColumn; // Value injected by FXMLLoader 

    @FXML // Add more contactsColumn to contactsColumn list 
    void addContactToAllContactsTextArea(ActionEvent event) { 

    } 

    @FXML 
    void editMeeting(ActionEvent event) { 

    } 

    @FXML 
    void loadInformationForMeeting(ActionEvent event) { 
     ObservableList<MeetingData> data = getMeetingData(); 

     this.meetingTable = new TableView<>(); 
     this.meetingTable.setItems(data); 

     this.placeColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("date")); 
     this.placeColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("place")); 
     this.categoryColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("category")); 
     this.contactsColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("contacts")); 
     this.commentsColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("comments")); 

     this.meetingTable.getColumns().add(this.dateAntTimeColumn); 
     this.meetingTable.getColumns().add(this.placeColumn); 
     this.meetingTable.getColumns().add(this.categoryColumn); 
     this.meetingTable.getColumns().add(this.contactsColumn); 
     this.meetingTable.getColumns().add(this.commentsColumn); 


//  // TODO: 01-Feb-17 delete this after finish 
//  for (MeetingData meetingData : data) { 
//   System.out.println(meetingData.getDate()); 
//   System.out.println(meetingData.getPlace()); 
//   System.out.println(meetingData.getCategory()); 
//   System.out.println(meetingData.getContacts()); 
//   System.out.println(meetingData.getComments()); 
//   System.out.println("----- END -----"); 
//   System.out.println(); 
//  } 
    } 

    // get all meetings 
    public ObservableList<MeetingData> getMeetingData() { 
     ObservableList<MeetingData> data = FXCollections.observableArrayList(); 
     data.add(new MeetingData("sdzgzrdbf", "sgzsfbs", "EDbfb", "sbdbf", "zbdd")); 
     data.add(new MeetingData("sEDGdb", "sgzsfbs", "EDbfb", "sbdbf", "zbdd")); 
     data.add(new MeetingData("sdzgsbfgzrdbf", "sgzsfbs", "EDbfb", "sbdbf", "zbdd")); 
     data.add(new MeetingData("zsrbd", "sgzsfbs", "EDbfb", "sbdbf", "zbdd")); 
     data.add(new MeetingData("rbdbdb", "sgzsfbs", "EDbfb", "sbdbf", "zbdd")); 
     data.add(new MeetingData("rsbdbd", "sgzsfbs", "EDbfb", "sbdbf", "zbdd")); 

     return data; 
    } 

    @FXML // This method is called by the FXMLLoader when initialization is complete 
    void initialize() { 
     assert dateAndTimeInformation != null : "fx:id=\"dateAndTimeInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert hoursInformation != null : "fx:id=\"hoursInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert minutesInformation != null : "fx:id=\"minutesInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert placeInformation != null : "fx:id=\"placeInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert categoryInformation != null : "fx:id=\"categoryInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert contactsInformation != null : "fx:id=\"contactsInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert allSelectedContactsTextArea != null : "fx:id=\"allSelectedContactsTextArea\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert commentInformation != null : "fx:id=\"commentInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert meetingTable != null : "fx:id=\"meetingTable\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert dateAntTimeColumn != null : "fx:id=\"dateAntTimeColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert placeColumn != null : "fx:id=\"placeColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert categoryColumn != null : "fx:id=\"categoryColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert contactsColumn != null : "fx:id=\"contactsColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 
     assert commentsColumn != null : "fx:id=\"commentsColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'."; 


    } 
} 

これは、データクラスです:

package application.meetings; 

public class MeetingData { 

    // Fields 
    private String date; 
    private String place; 
    private String category; 
    private String contacts; 
    private String comments; 

    // Constructors 
    public MeetingData(String date, String place, String category, String contacts, String comments) { 
     this.date = date; 
     this.place = place; 
     this.category = category; 
     this.contacts = contacts; 
     this.comments = comments; 
    } 

    // Setters 
    public void setDate(String date) { 
     this.date = date; 
    } 

    public void setPlace(String place) { 
     this.place = place; 
    } 

    public void setCategory(String category) { 
     this.category = category; 
    } 

    public void setContacts(String contacts) { 
     this.contacts = contacts; 
    } 

    public void setComments(String comments) { 
     this.comments = comments; 
    } 

    // Getters 
    public String getDate() { 
     return date; 
    } 

    public String getPlace() { 
     return place; 
    } 

    public String getCategory() { 
     return category; 
    } 

    public String getContacts() { 
     return contacts; 
    } 

    public String getComments() { 
     return comments; 
    } 

} 

そして最後にFXMLファイル:

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.geometry.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.control.cell.PropertyValueFactory?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.text.Font?> 
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="450.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controllers.EditMeetingPopUpController"> 
    <bottom> 
     <HBox alignment="CENTER_RIGHT" BorderPane.alignment="CENTER"> 
     <children> 
      <Button mnemonicParsing="false" onAction="#loadInformationForMeeting" text="Зареди информация"> 
       <HBox.margin> 
        <Insets right="10.0" /> 
       </HBox.margin> 
      </Button> 
      <Button defaultButton="true" mnemonicParsing="false" onAction="#editMeeting" prefWidth="80.0" text="Редактирай"> 
       <HBox.margin> 
        <Insets /> 
       </HBox.margin></Button> 
     </children> 
     <BorderPane.margin> 
      <Insets /> 
     </BorderPane.margin> 
     </HBox> 
    </bottom> 
    <center> 
     <VBox alignment="CENTER"> 
     <children> 
      <HBox alignment="CENTER_LEFT"> 
       <children> 
        <Label prefWidth="70.0" text="Дата" /> 
        <DatePicker fx:id="dateAndTimeInformation" prefWidth="220.0" promptText="Дата" showWeekNumbers="true"> 
        <HBox.margin> 
         <Insets left="20.0" /> 
        </HBox.margin> 
        <tooltip> 
         <Tooltip text="Полето е задължително" /> 
        </tooltip> 
        </DatePicker> 
       </children> 
       <VBox.margin> 
        <Insets bottom="10.0" /> 
       </VBox.margin> 
      </HBox> 
      <HBox alignment="CENTER_LEFT"> 
       <children> 
        <Label prefWidth="70.0" text="Час" /> 
        <ComboBox fx:id="hoursInformation" prefWidth="70.0"> 
        <HBox.margin> 
         <Insets left="20.0" right="5.0" /> 
        </HBox.margin> 
        <tooltip> 
         <Tooltip text="Полето е задължително" /> 
        </tooltip> 
        </ComboBox> 
        <Label text="часa"> 
        <HBox.margin> 
         <Insets right="20.0" /> 
        </HBox.margin> 
        </Label> 
        <ComboBox fx:id="minutesInformation" prefWidth="70.0"> 
        <HBox.margin> 
         <Insets right="5.0" /> 
        </HBox.margin> 
        <tooltip> 
         <Tooltip text="Полето е задължително" /> 
        </tooltip> 
        </ComboBox> 
        <Label text="мин."> 
        <HBox.margin> 
         <Insets /> 
        </HBox.margin> 
        </Label> 
       </children> 
       <VBox.margin> 
        <Insets bottom="10.0" /> 
       </VBox.margin> 
      </HBox> 
      <HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="218.0"> 
       <children> 
        <Label prefWidth="70.0" text="Място" /> 
        <TextField fx:id="placeInformation" prefWidth="220.0" promptText="Място на срещата"> 
        <HBox.margin> 
         <Insets left="20.0" /> 
        </HBox.margin> 
        </TextField> 
       </children> 
       <VBox.margin> 
        <Insets bottom="10.0" /> 
       </VBox.margin> 
      </HBox> 
      <HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="253.0"> 
       <children> 
        <Label prefWidth="70.0" text="Категория" /> 
        <ComboBox fx:id="categoryInformation" prefWidth="220.0" promptText="Изберете категория"> 
        <HBox.margin> 
         <Insets left="20.0" /> 
        </HBox.margin> 
        </ComboBox> 
       </children> 
       <VBox.margin> 
        <Insets bottom="10.0" /> 
       </VBox.margin> 
      </HBox> 
      <HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="240.0"> 
       <children> 
        <Label prefWidth="70.0" text="Участници" /> 
        <ComboBox fx:id="contactsInformation" onAction="#addContactToAllContactsTextArea" prefWidth="220.0" promptText="Изберете участници"> 
        <HBox.margin> 
         <Insets left="20.0" /> 
        </HBox.margin> 
        <tooltip> 
         <Tooltip text="Полето е задължително" /> 
        </tooltip> 
        </ComboBox> 
       </children> 
       <VBox.margin> 
        <Insets bottom="10.0" /> 
       </VBox.margin> 
      </HBox> 
      <HBox> 
       <children> 
        <Pane prefHeight="100.0" prefWidth="70.0" /> 
        <TextArea fx:id="allSelectedContactsTextArea" editable="false" prefHeight="100.0" prefWidth="220.0" promptText="Участници в срещата"> 
        <HBox.margin> 
         <Insets left="20.0" /> 
        </HBox.margin> 
        </TextArea> 
       </children> 
       <VBox.margin> 
        <Insets bottom="10.0" /> 
       </VBox.margin> 
      </HBox> 
      <HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="293.0"> 
       <children> 
        <Label alignment="TOP_LEFT" prefHeight="100.0" prefWidth="70.0" text="Коментар" /> 
        <TextArea fx:id="commentInformation" prefHeight="100.0" prefWidth="220.0" promptText="Въведете коментар"> 
        <HBox.margin> 
         <Insets bottom="10.0" left="20.0" /> 
        </HBox.margin> 
        <tooltip> 
         <Tooltip text="Полето е задължително" /> 
        </tooltip> 
        </TextArea> 
       </children> 
       <VBox.margin> 
        <Insets /> 
       </VBox.margin> 
      </HBox> 
     </children> 
     </VBox> 
    </center> 
    <left> 
     <VBox BorderPane.alignment="CENTER"> 
     <BorderPane.margin> 
      <Insets /> 
     </BorderPane.margin> 
     </VBox> 
    </left> 
    <padding> 
     <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" /> 
    </padding> 
    <top> 
     <Label alignment="CENTER" prefWidth="600.0" text="Моля изберете среща за редактиране"> 
     <font> 
      <Font name="System Bold" size="14.0" /> 
     </font> 
     <BorderPane.margin> 
      <Insets bottom="10.0" left="360.0" /> 
     </BorderPane.margin> 
     </Label> 
    </top> 
    <right> 
     <TableView fx:id="meetingTable" editable="true" prefWidth="600.0" BorderPane.alignment="CENTER"> 
     <columns> 
      <TableColumn fx:id="dateAntTimeColumn" prefWidth="75.0" text="Дата и час" > 
       <cellValueFactory> 
        <PropertyValueFactory property="date" /> 
       </cellValueFactory> 
      </TableColumn> 
      <TableColumn fx:id="placeColumn" prefWidth="75.0" text="Място" > 
       <cellValueFactory> 
        <PropertyValueFactory property="place" /> 
       </cellValueFactory> 
      </TableColumn> 
      <TableColumn fx:id="categoryColumn" prefWidth="75.0" text="Категория" > 
       <cellValueFactory> 
        <PropertyValueFactory property="category" /> 
       </cellValueFactory> 
      </TableColumn> 
      <TableColumn fx:id="contactsColumn" prefWidth="75.0" text="Участници" > 
       <cellValueFactory> 
        <PropertyValueFactory property="contacts" /> 
       </cellValueFactory> 
      </TableColumn> 
      <TableColumn fx:id="commentsColumn" prefWidth="114.0" text="Коментар" > 
       <cellValueFactory> 
        <PropertyValueFactory property="comments" /> 
       </cellValueFactory> 
      </TableColumn> 
     </columns> 
     <BorderPane.margin> 
      <Insets bottom="10.0" /> 
     </BorderPane.margin> 
     <columnResizePolicy> 
      <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> 
     </columnResizePolicy> 
     </TableView> 
    </right> 
</BorderPane> 

あなたは私を助けることができる場合、私は非常に感謝されると間違いがどこから来たのか説明してください。

+0

のですか? – Phil

+0

ObservableListのコンソールから何かを印刷しようとしましたが、テーブルにロードできません。 MeetingDataクラスのStringをSimpleStringPropertyに変更し、defaulコンストラクタを作成し、getterとsetterを変更して、何も起こっていません。テーブルの中に "No content in table"と書いてあります。 – Phil

+0

私はもう一度変更を試みました – Phil

答えて

1

まず、あなたのloadInformationforMeeting()方法は、新しいTableViewを作成し、そこにデータを追加する、(...彼らはすでに持っている同じ設定で)表の列を再構成し、新しいテーブルにテーブル列を追加します。

ただし、新しいテーブルはUIに配置されないため、データは表示されません。新しいテーブルを作成する必要はありません。

第2に、既存のテーブル(FXMLファイルで定義されているテーブル)を使用すると、すでに列が追加されており、それらの列にはすでにセル値ファクトリがあります。したがって、列をテーブルに再度追加する必要はなく、列の構成を繰り返す必要はありません。

必要なのはそれで何をしようとする

@FXML 
void loadInformationForMeeting(ActionEvent event) { 
    ObservableList<MeetingData> data = getMeetingData(); 
    this.meetingTable.setItems(data); 
} 
関連する問題