JavaFx TableView数据在面向对象设计中不可见

时间:2015-08-01 10:31:47

标签: java javafx javafx-2 javafx-8 fxml

表格视图数据显示(来自数据库)以及我在控制器中输入代码时的情况。 但是如果尝试OOP设计数据来自数据库但它隐藏了。 如果我点击一行,那么我可以看到System.out.println();

选择了哪一行

听到我的文件和代码。

  

Supplyer.java //object

public ObservableList<SupplyerList> supplyerDetails = FXCollections.observableArrayList();

public void view() {
        DBConnection dbCon = new DBConnection();
        Connection con;
        PreparedStatement pst;
        ResultSet rs;
        try {
            con = dbCon.geConnection();
            pst = con.prepareCall("select * from Supplyer");
            rs = pst.executeQuery();
            while (rs.next())
                supplyerDetails.addAll(new SupplyerList(rs.getString(1),rs.getString(2)));
            }

        } catch (SQLException ex) {
            Logger.getLogger(Supplyer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
  

SupplyerController.java ControllerClass

@FXML private TableView<SupplyerList> tblSupplyer;
@FXML private TableColumn<SupplyerList, String> clmSUpplyerId;
@FXML private TableColumn<SupplyerList, String> clmSupplyerName;

public void showDetails() {

        clmSUpplyerId.setCellValueFactory(new PropertyValueFactory<SupplyerList, String>("supplyerId"));
        clmSUpplyerId.setCellValueFactory(new PropertyValueFactory<SupplyerList, String>("supplyerName"));
        tblSupplyer.setItems(supplyer.supplyerDetails);

        supplyer.view();
    }
  

SupplyerList object for table view

public class SupplyerList {

    private final SimpleStringProperty supplyerId;
    private final SimpleStringProperty supplyerName;



    public String getSupplyerId() {
        return supplyerId.get();
    }

    public SimpleStringProperty supplyerIdProperty() {
        return supplyerId;
    }

    public void setSupplyerId(String supplyerId) {
        this.supplyerId.set(supplyerId);
    }

    public String getSupplyerName() {
        return supplyerName.get();
    }

    public SimpleStringProperty supplyerNameProperty() {
        return supplyerName;
    }

    public void setSupplyerName(String supplyerName) {
        this.supplyerName.set(supplyerName);
    }

    public SupplyerList(String supplyerId, String supplyerName) {
        this.supplyerId = new SimpleStringProperty(supplyerId);
        this.supplyerName = new SimpleStringProperty(supplyerName);
    }

0 个答案:

没有答案