TableColumns在TableView中不可见,但在Scene Builder中可见

时间:2016-05-24 08:19:08

标签: java javafx javafx-8 scenebuilder

我面临一个奇怪的问题。我正在使用最新的Gluon SceneBuilder for JavaFX。

在我的场景中,我有一个包含11列的Tableview。所有Colums都在Scene Builder中可见,但是一旦我运行Application,就没有可见的列。只有一个空白栏,给定的列名应该是。是的,我在保存SceneBuilder FXML文件后做了刷新。

包含Controller和fx的场景构建器设置:TableColumns和TableView的id是正确的。我错过了什么?

SceneBuilder预览:

现实生活:

enter image description here

FXML:

pb

控制器:

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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>

<GridPane prefHeight="700.0" prefWidth="1150.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="arrivals.ArrivalsController">
   <rowConstraints>
      <RowConstraints percentHeight="5.0" vgrow="ALWAYS" />
      <RowConstraints vgrow="ALWAYS" />
      <RowConstraints percentHeight="5.0" vgrow="ALWAYS" />
   </rowConstraints>
   <columnConstraints>
      <ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
   </columnConstraints>
   <children>
      <HBox GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">
         <children>
            <Label text="Show Period" HBox.hgrow="ALWAYS">
               <HBox.margin>
                  <Insets left="5.0" top="10.0" />
               </HBox.margin>
            </Label>
            <ChoiceBox fx:id="periodBox" onAction="#populateTable" prefWidth="150.0" HBox.hgrow="ALWAYS">
               <HBox.margin>
                  <Insets left="5.0" top="5.0" />
               </HBox.margin>
            </ChoiceBox>
            <Separator orientation="VERTICAL" prefHeight="200.0" HBox.hgrow="ALWAYS">
               <HBox.margin>
                  <Insets left="10.0" />
               </HBox.margin>
            </Separator>
            <Label text="From" HBox.hgrow="ALWAYS">
               <HBox.margin>
                  <Insets left="5.0" top="10.0" />
               </HBox.margin>
            </Label>
            <DatePicker fx:id="from" HBox.hgrow="ALWAYS">
               <HBox.margin>
                  <Insets left="5.0" top="5.0" />
               </HBox.margin>
            </DatePicker>
            <Label text="To" HBox.hgrow="ALWAYS">
               <HBox.margin>
                  <Insets left="5.0" top="10.0" />
               </HBox.margin>
            </Label>
            <DatePicker fx:id="to" HBox.hgrow="ALWAYS">
               <HBox.margin>
                  <Insets left="5.0" top="5.0" />
               </HBox.margin>
            </DatePicker>
            <Button minWidth="80.0" mnemonicParsing="false" onAction="#picker" text="Show">
               <HBox.margin>
                  <Insets left="10.0" top="5.0" />
               </HBox.margin>
            </Button>
         </children>
      </HBox>
      <TableView fx:id="arvtable" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.vgrow="ALWAYS">
         <columns>
            <TableColumn fx:id="bookingId" prefWidth="75.0" text="Booking ID" />
            <TableColumn fx:id="firstName" prefWidth="75.0" text="First Name" />
            <TableColumn fx:id="lastName" prefWidth="75.0" text="Last Name" />
            <TableColumn fx:id="arrival" prefWidth="75.0" text="Arrival" />
            <TableColumn fx:id="checkout" prefWidth="75.0" text="Checkout" />
            <TableColumn fx:id="roomNumber" prefWidth="75.0" text="Room Number" />
            <TableColumn fx:id="roomType" prefWidth="75.0" text="Room Type" />
            <TableColumn fx:id="nights" prefWidth="75.0" text="Nights" />
            <TableColumn fx:id="breakfast" prefWidth="75.0" text="Breakfast" />
            <TableColumn fx:id="amount" prefWidth="75.0" text="Amount" />
            <TableColumn fx:id="comment" prefWidth="75.0" text="Comments" />
         </columns></TableView>
      <HBox prefHeight="100.0" prefWidth="200.0" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2" GridPane.vgrow="ALWAYS">
         <children>
            <Button minWidth="80.0" mnemonicParsing="false" text="Modify">
               <HBox.margin>
                  <Insets left="10.0" top="5.0" />
               </HBox.margin>
            </Button>
            <Button minWidth="80.0" mnemonicParsing="false" onAction="#cancel" text="Cancel">
               <HBox.margin>
                  <Insets left="10.0" top="5.0" />
               </HBox.margin>
            </Button>
            <Button minWidth="80.0" mnemonicParsing="false" text="Check-In">
               <HBox.margin>
                  <Insets left="10.0" top="5.0" />
               </HBox.margin>
            </Button>
         </children></HBox>
   </children>
</GridPane>

数据模型:

public class ArrivalsController implements Initializable{

    final ObservableList<ArrivalRecord> data = FXCollections.observableArrayList();


    @FXML   TableView<ArrivalRecord> arvtable;
    @FXML   TableColumn<ArrivalRecord, String> bookingId;
    @FXML   TableColumn<ArrivalRecord, String> firstName;
    @FXML   TableColumn<ArrivalRecord, String> lastName;
    @FXML   TableColumn<ArrivalRecord, String> arrival;
    @FXML   TableColumn<ArrivalRecord, String> checkout;
    @FXML   TableColumn<ArrivalRecord, String> roomNumber;
    @FXML   TableColumn<ArrivalRecord, String> roomType;
    @FXML   TableColumn<ArrivalRecord, String> nights;
    @FXML   TableColumn<ArrivalRecord, String> breakfast;
    @FXML   TableColumn<ArrivalRecord, String> amount;
    @FXML   TableColumn<ArrivalRecord, String> comment;




    @Override
    public void initialize(URL location, ResourceBundle resources) {

        bookingId.setCellValueFactory(cellData -> cellData.getValue().getBidProperty());
        firstName.setCellValueFactory(cellData -> cellData.getValue().getFirstNameProperty());
        lastName.setCellValueFactory(cellData -> cellData.getValue().getLastNameProperty());
        arrival.setCellValueFactory(cellData -> cellData.getValue().getArrivalProperty());
        checkout.setCellValueFactory(cellData -> cellData.getValue().getCheckoutProperty());
        roomNumber.setCellValueFactory(cellData -> cellData.getValue().getRoomNumberProperty());
        roomType.setCellValueFactory(cellData -> cellData.getValue().getRoomTypeProperty());
        nights.setCellValueFactory(cellData -> cellData.getValue().getNightsProperty());
        breakfast.setCellValueFactory(cellData -> cellData.getValue().getBreakfastProperty());
        amount.setCellValueFactory(cellData -> cellData.getValue().getAmountProperty());
        comment.setCellValueFactory(cellData -> cellData.getValue().getCommentProperty());

    }

0 个答案:

没有答案