[英]JavaFX With Scene builder Controller Error About addAll?
将 JavaFX 与 Scene Builder 一起使用时出现错误。 我不明白为什么我收到错误。 我认为方法addAll()
有问题。
public class FXML_PatientListController implements Initializable {
private Room rr=null;
@FXML
private TextArea p_id;
@FXML
private TextArea p_name;
@FXML
private TextArea sk;
@FXML
private Button enter;
@FXML
private Button delete;
@FXML
private TableView<?> list;
@FXML
private TableColumn<?, ?> p_id_T;
@FXML
private TableColumn<?, ?> p_name_T;
@FXML
private TableColumn<?, ?> Sk_T;
@FXML
private void close (ActionEvent av){
System.exit(0);
}
/**
* Initializes the controller class.
*/
public void setPatientInfo(Room r) {
rr = r;
showPatients(null);
}
public void showPatients(Event s) {
list.getItems().clear();
if (rr != null) {
list.getItems().addAll(rr.getPatient()); // I get a error here.
}
}
和错误:
no suitable method found for addAll(ArrayList<Patient>) method List.addAll(Collection<? extends CAP#1>) is not applicable (argument mismatch; ArrayList<Patient> cannot be converted to Collection<? extends CAP#1>) method ObservableList.addAll(CAP#1...) is not applicable (varargs mismatch; ArrayList<Patient> cannot be converted to CAP#1) where CAP#1 is a fresh type-variable: CAP#1 extends Object from capture of ? ---- (Alt-Enter shows hints)
我从面向对象的课程中得到了这个项目。
我认为在添加数据之前,您还有一些事情需要处理。 您需要键入将您的列分配给 Patient 类和每个字段类型。 下面的一些 sudo 代码...
@FXML
private TableView<Patient> tbl;
@FXML
private TableColumn< Patient, String> patientName;
private final ObservableList< Patient > tblData = FXCollections.observableArrayList();
@Override
public void initialize(URL url, ResourceBundle rb) {
setPatientName(patientName);
tbl.setItems(tblData);
}
/**
* Use this method to set the column properties. You should of course make this generic but just by way of an example...
*/
public static void setPatientName(TableColumn< Patient, String> column) {
column.setCellValueFactory(new PropertyValueFactory<>("patientName"));
column.setCellFactory(TextFieldTableCell.forTableColumn());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.