1 回答

TA貢獻1794條經驗 獲得超7個贊
要訪問textArea嵌套的 fxml,您必須更改控制器:
public class ControllerSample {
@FXML
private TextArea textAreaSample;
@FXML
private ControllerSending sendingController;
public ControllerSample() {
}
public TextArea getTextAreaSample() {
return textAreaSample;
}
public void setTextAreaSample(TextArea textAreaSample) {
this.textAreaSample = textAreaSample;
}
protected ControllerSending getSendingController() {
return sendingController;
}
}
public class ControllerSending {
@FXML
private ControllerSendingPhotos sendingPhotosController;
public ControllerSending() {
}
protected ControllerSendingPhotos getSendingPhotosController() {
return sendingPhotosController;
}
}
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loaderSample = new FXMLLoader(getClass().getResource("sample.fxml"));
Parent root = loaderSample.load();
ControllerSample controllerSample = (ControllerSample) loaderSample.getController();
TextArea textAreaSample = controllerSample.getTextAreaSample();
textAreaSample.setText("\ndebug textAreaSample\n");
TextArea textAreaSendingPhotos = controllerSample.getSendingController().getSendingPhotosController()
.getTextAreaSendingPhotos();
textAreaSendingPhotos.setText("test test test");
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 800, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
添加回答
舉報