Rows not showing when initialized to TableView in JavaFX

时间:2018-01-23 19:21:48

标签: java javafx

I'm trying to add on initialize values in TableView and they are created added, but values don't show.

Controler:

public class OrdersController {
    @FXML
    private TableView<OrdersTable> table;
    @FXML
    private TableColumn<OrdersTable, String> columnNoId;
    @FXML
    private TableColumn<OrdersTable, String> columnStartId;
    @FXML
    private TableColumn<OrdersTable, String> columnDriverId;
    @FXML
    private TableColumn<OrdersTable, String> columnAddressId;
    @FXML
    private TableColumn<OrdersTable, Double> columnPriceId;
    @FXML
    private TableColumn<OrdersTable, String> columnWayOfPayIs;
    @FXML
    private Button cancelOrder;
    @FXML
    private Button acceptOrder;
    @FXML
    private Button unassign;
    @FXML
    private Label totalPrice;
    ObservableList<OrdersTable> data = FXCollections.observableArrayList();

    @FXML
    public void initialize() {
        columnNoId.setCellValueFactory(new PropertyValueFactory<OrdersTable, String>("rNo"));
        columnStartId.setCellValueFactory(new PropertyValueFactory<OrdersTable, String>("rTime"));
        columnDriverId.setCellValueFactory(new PropertyValueFactory<OrdersTable, String>("rDriver"));
        columnAddressId.setCellValueFactory(new PropertyValueFactory<OrdersTable, String>("rAddress"));
        columnPriceId.setCellValueFactory(new PropertyValueFactory<OrdersTable, Double>("rPrice"));
        columnWayOfPayIs.setCellValueFactory(new PropertyValueFactory<OrdersTable, String>("rMethod"));
        table.setPlaceholder(new Label("No orders"));
        table.setItems(data);
        addDataToTable();
    }

    public void addDataToTable() {
        List<Orders> ordersList = new ArrayList<>();
        try {
            ordersList = MySQLOperations.getOrdersList(Main.orderStatus, Main.orderType);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        Integer i = 1;
        for (Orders o : ordersList) {
            data.add(new OrdersTable(i.toString(), o.getTimeOfOrder().toString(), o.getAddress(),
                    o.getDesignedDriver().getForename(), o.getSubTotal(), "Cash"));
            i++;
        }

    }

}

OrdersTable.class

public class OrdersTable {
    private SimpleStringProperty rNo;
    private SimpleStringProperty rTime;
    private SimpleStringProperty rDriver;
    private SimpleStringProperty rAddress;
    private SimpleDoubleProperty rPrice;
    private SimpleStringProperty rMethod;

    public OrdersTable(String rNo, String rTime, String rDriver, String rAddress, Double rPrice, String rMethod) {
        // super();
        this.rNo = new SimpleStringProperty(rNo);
        this.rTime = new SimpleStringProperty(rTime);
        this.rDriver = new SimpleStringProperty(rDriver);
        this.rAddress = new SimpleStringProperty(rAddress);
        this.rPrice = new SimpleDoubleProperty(rPrice);
        this.rMethod = new SimpleStringProperty(rMethod);
    }

    public SimpleStringProperty getrNo() {
        return rNo;
    }

    public void setrNo(SimpleStringProperty rNo) {
        this.rNo = rNo;
    }

    public SimpleStringProperty getrTime() {
        return rTime;
    }

    public void setrTime(SimpleStringProperty rTime) {
        this.rTime = rTime;
    }

    public SimpleStringProperty getrDriver() {
        return rDriver;
    }

    public void setrDriver(SimpleStringProperty rDriver) {
        this.rDriver = rDriver;
    }

    public SimpleStringProperty getrAddress() {
        return rAddress;
    }

    public void setrAddress(SimpleStringProperty rAddress) {
        this.rAddress = rAddress;
    }

    public SimpleDoubleProperty getrPrice() {
        return rPrice;
    }

    public void setrPrice(SimpleDoubleProperty rPrice) {
        this.rPrice = rPrice;
    }

    public SimpleStringProperty getrMethod() {
        return rMethod;
    }

    public void setrMethod(SimpleStringProperty rMethod) {
        this.rMethod = rMethod;
    }

}

Table after initialize:

Table after initialize

0 个答案:

没有答案