I would like to ask you, if I can obtain a TextArea defined in my sample.fxml file from start() method, where I have defined FXMLoader and primary stage. I need to obtain the TextArea object there and set on it some String which I have saved into file before.
Thank you guys!
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/fxml/sample.fxml"));
primaryStage.setTitle("Appilcation");
primaryStage.setScene(new Scene(root, 420, 330));
primaryStage.setResizable(true);
root.getChildrenUnmodifiable().
// get the TextArea and set text on it which I will get from file
}
public static void main(String[] args) {
launch(args);
}
}
And here is my .fxml file
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane fx:controller="sample.PDPController" xmlns:fx="http://javafx.com/fxml" hgap="2" vgap="3" styleClass="root">
<padding><Insets top="5" right="15" bottom="5" left="15"/></padding>
<Text id="welcome-text" text="Welcome user!"
GridPane.columnIndex="0"
GridPane.rowIndex="0"
GridPane.columnSpan="1"
GridPane.halignment="CENTER"
/>
<Text id="welcome-text-secondary" text="Count data..."
GridPane.columnIndex="0"
GridPane.rowIndex="1"
GridPane.columnSpan="1"
GridPane.halignment="CENTER"
/>
<TextArea fx:id="timeInputId" minHeight="200" minWidth="200" wrapText="true"
promptText="Insert data in specified format." focusTraversable="false"
GridPane.columnIndex="0"
GridPane.rowIndex="2"
GridPane.columnSpan="1"
GridPane.halignment="CENTER"
/>
<HBox spacing="10" alignment="bottom_left"
GridPane.columnIndex="0"
GridPane.rowIndex="5"
GridPane.columnSpan="1">
<Button text="Počítej" onAction="#handleSubmitButtonAction"/>
<Button text="Ulož" onAction="#handleSaveButtonAction"/>
</HBox>
<Text fx:id="actionTarget"
GridPane.columnIndex="0"
GridPane.rowIndex="6"
GridPane.columnSpan="1"
GridPane.halignment="CENTER"
/>
<stylesheets>
<URL value="@../styles.css" />
</stylesheets>
</GridPane>