我是javafx的新手,所以请忽略我的愚蠢问题,这是我面临的问题,从2天开始,如果有任何身体帮助我,我们会很好吗 我在那个国家的超级父母(主视图)fxml视图获取加载器 在国家fxml我有一个加载到国家的fxml(调用表) 当用户点击表视图的任何数据新fxml文件加载和该文件我想加载到父我已经使用超级父堆栈窗格ID它抛出一个错误请帮助我为什么这发生任何解决方案链接,代码或建议它会节省我的一天 这是代码
ObservableList<addcountryController> data = FXCollections.observableArrayList();
private Pagination pagination;
@FXML
private AnchorPane cresult;
@FXML
private StackPane stackconsearch;
@FXML
private StackPane stackhome;
@FXML
private AnchorPane stackanc;
@FXML
private StackPane stackcountry;
@FXML
private TableView<addcountryController> tableUser;
@FXML
private TableColumn<addcountryController, String> columnName;
@FXML
private TableColumn<addcountryController, String> columnDesc;
DatabaseHandler databaseHandler;
public void setText(String first,String sec){
this.country.setText(first);
this.desc.setText(sec);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
databaseHandler = DatabaseHandler.getInstance();
initCol();
String qu = "SELECT * FROM country_tbl ";
ResultSet rs = databaseHandler.execQuery(qu);
try {
while (rs.next()) {
String id= rs.getString("id");
String name= rs.getString("countryname");
String description = rs.getString("descr");
String country2char= rs.getString("country2char");
String descrshort = rs.getString("descrshort");
data.add(new addcountryController(id,name, description,country2char,descrshort));
}
}catch (SQLException ex) {
Logger.getLogger(addcountryController.class.getName()).log(Level.SEVERE, null, ex);
}
tableUser.setItems(null);
tableUser.setItems(data);
tableUser.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
tableUser.getSelectionModel().getSelectedItems().addListener(new ListChangeListener<addcountryController>() {
public void onChanged(ListChangeListener.Change<? extends addcountryController> c) {
try {
Stage primaryStage=new Stage();
FXMLLoader loader =new FXMLLoader();
loader.load(getClass().getResource("/region/updatecountry.fxml").openStream());
updatecountryController usercontroller=(updatecountryController)loader.getController();
for (addcountryController p : c.getList()) {
String ADDID=p.getId();
String ADD=p.getName();
String ADD1=p.getDescriptionshort();
String ADD2=p.getDescription();
String ADD3=p.getCountrychar();
usercontroller.setText(ADDID,ADD,ADD1,ADD2,ADD3);
}
StackPane root = loader.getRoot();
stackconsearch.getChildren().clear();
stackconsearch.getChildren().add(root);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
这是我的编辑控制器
private StackPane stackhome;
@FXML
private StackPane stackconsearch;
@FXML
private AnchorPane cresult;
@FXML
private TextField country;
@FXML
private TextField desc;
public void add(ActionEvent event) {
String ADD=countrycode.getText();
try {
if(ADD.isEmpty()){
Alert alert=new Alert(Alert.AlertType.ERROR);
alert.setHeaderText(null);
alert.setContentText("Please Fill All DATA");
alert.showAndWait();
return;
}
FXMLLoader loader =new FXMLLoader();
loader.load(getClass().getResource("/region/newCountry.fxml").openStream());
MainController usercontroller=(MainController)loader.getController();
usercontroller.setText(ADD);
StackPane root = loader.getRoot();
stackconsearch.getChildren().clear();
stackconsearch.getChildren().add(root);
}catch(Exception e) {
e.printStackTrace();
}
}
public void search(ActionEvent event) {
String countrytxt=country.getText();
String desctxt=desc.getText();
if(countrytxt.isEmpty() && desctxt.isEmpty()) {
try{
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.load(getClass().getResource("/region/cresult.fxml").openStream());
StackPane root = fxmlLoader.getRoot();
root.getStylesheets().add(getClass().getResource("/application/application.css").toExternalForm());
countryController usercontroller=(countryController)fxmlLoader.getController();
usercontroller.setText(countrytxt,desctxt);
cresult.getChildren().clear();
cresult.getChildren().add(root);
}catch(IOException e){
e.printStackTrace();
}
}else{
try{
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.load(getClass().getResource("/region/cresult.fxml").openStream());
StackPane root = fxmlLoader.getRoot();
countryController usercontroller=(countryController)fxmlLoader.getController();
usercontroller.setText(countrytxt,desctxt);
cresult.getChildren().clear();
cresult.getChildren().add(root);
}catch(IOException e){
e.printStackTrace();
}
}
}
这里是主控制器
@FXML
private StackPane stackhome;
@FXML
private AnchorPane Mainview;
@FXML
private AnchorPane stackanc;
@Override
public void start(Stage primaryStage) {
try {
Parent root =FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
@FXML
public void country(ActionEvent event) {
FXMLLoader fxmlLoader = new FXMLLoader();
try {
fxmlLoader.load(getClass().getResource("/region/country.fxml").openStream());
} catch (IOException e) {
}
StackPane root = fxmlLoader.getRoot();
stackhome.getChildren().clear();
stackhome.getChildren().add(root);
}
public static void main(String[] args) {
launch(args);
}
这里是stackhome是超级父级,stackcountry是超级父级的父级和子级,我还有一个父stacksub,它是stackhome,stackcountry的子级,它有一个叫做stackchild的子项我想把这个stackchild加载到stackhome但是它不是提出任何建议