问题描述
我想创建一个方法,该方法将在borderpane中返回一个表 ,但是我得到了空表,并且它的标签显示在GUI上。 这是代码:
@Override
public void start(Stage stage) throws Exception {
borderpane border = new borderpane();
VBox cBox = addCBox(); //center Box
border.setCenter(cBox);
Scene scene = new Scene(border,600,650);
stage.setTitle("Test Project"); // Set the stage title
stage.setScene(scene); // Place the scene in the stage
stage.show(); // display the stage
}
这是我通过遵循文档创建表数据和方法的方式:
private final TableView<Doctor> table = new TableView<>();
private final ObservableList<Doctor> data = FXCollections.observableArrayList(
new Doctor("196","Daniel LW","Cardiologists","9-6","MBBCh"),new Doctor("197","James DN","Anesthesiologists","4-9","LRCP"),new Doctor("199","Chales AK","Dermatologists","6-12","BSc")
);
public static void main(String[] args) {
launch(args);
}
public VBox addCBox() {
final Label label = new Label("Doctor List");
label.setFont(new Font("Arial",20));
table.setEditable(true);
TableColumn<Doctor,String> col1 = new TableColumn<Doctor,String>("ID");
col1.setMinWidth(30);
col1.setMaxWidth(60);
col1.setCellValueFactory(new PropertyValueFactory<>("id"));
TableColumn<Doctor,String> col2 = new TableColumn<Doctor,String>("NAME");
col2.setMinWidth(100);
col2.setCellValueFactory(new PropertyValueFactory<>("name"));
table.setItems(data);
table.getColumns().addAll(col1,col2);
// the above line prompt me warning message,but although I use:
// table.getColumns().add(col1); table.getColumns().add(col2);
// the rows of data still not visible
// I only get the empty clickable rows
final VBox cBox = new VBox();
cBox.setPadding(new Insets(10,20,10,10));
cBox.getChildren().addAll(label,table);
return cBox;
}
这是我创建的类的简化版本。有设置者和获取者。
public static class Doctor {
private SimpleStringProperty id,name,specialist,workTime,qualification;
public Doctor(String id,String name,String specialist,String workTime,String qualification) {
this.id = new SimpleStringProperty(id);
this.name = new SimpleStringProperty(name);
this.specialist = new SimpleStringProperty(specialist);
this.workTime = new SimpleStringProperty(workTime);
this.qualification = new SimpleStringProperty(qualification);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)