我想将我的 FXML 分成更小的文件,每个文件都有自己的控制器。在 main 中,我为每个控制器创建实例并访问textAreaSample并尝试附加文本。我没有看到文字正在改变。为什么?Alert正在显示来自此的文本TextArea:
alert.setContentText(textAreaSample.getText());
我不知道如何设置所有 fxml 文件和控制器。我应该如何设置这一切?
这是我的主要“sample.fxml”文件:
<GridPane fx:controller="sample.ControllerSample"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<fx:include fx:id="sending" source="Sending.fxml" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<TextArea fx:id="textAreaSample" prefWidth="200" prefHeight="200"
GridPane.columnIndex="1" GridPane.rowIndex="0" text="Sample">
</TextArea>
</GridPane>
及其控制器:
public class ControllerSample {
@FXML
private TextArea textAreaSample;
public ControllerSample() {}
public TextArea getTextAreaSample() {
return textAreaSample;
}
public void setTextAreaSample(TextArea textAreaSample) {
this.textAreaSample = textAreaSample;
}
}
现在我有Sending.fxml文件:
<GridPane fx:controller="sample.ControllerSending"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<fx:include fx:id="sendingPhotos" source="SendingPhotos.fxml" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
</GridPane>
及其控制器:
public class ControllerSending {
public ControllerSending() {}
}
这是SendingPhotos.fxml代码:
<TextArea xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="sample.ControllerSendingPhotos" fx:id="textAreaSendingPhotos" prefWidth="200" prefHeight="200"
text="Photos"/>
和控制器:
public class ControllerSendingPhotos {
@FXML
private TextArea textAreaSendingPhotos;
public ControllerSendingPhotos() {}
public TextArea getTextAreaSendingPhotos() {
return textAreaSendingPhotos;
}
public void setTextAreaSendingPhotos(TextArea textAreaSendingPhotos) {
this.textAreaSendingPhotos = textAreaSendingPhotos;
}
}
跃然一笑
慕田峪9158850
随时随地看视频慕课网APP
相关分类