There is a Scene where there is a label and a button to set on Action.when the button is pressed the next Scene loads and in the next Scene there is a label which is needed to show the text on the first label.this may be a dplicate Passing Parameters JavaFX FXML but i cant seams to get it if you can take some time off to help out please write how to change the code
First Scene Fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="177.0" prefWidth="325.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller">
<children>
<Button fx:id="btn1" layoutX="128.0" layoutY="126.0" mnemonicParsing="false" onAction="#button23" text="Button" />
<Label fx:id="lbl1" layoutX="108.0" layoutY="65.0" text="Example" />
</children>
</AnchorPane>
Second Scene Fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="158.0" prefWidth="196.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65">
<children>
<Label fx:id="lbl2" layoutX="57.0" layoutY="71.0" prefHeight="17.0" prefWidth="105.0" text="Label" />
</children>
</AnchorPane>
Button Controller code
public class controller {
@FXML
private Label lbl1,lbl2;
@FXML
private Button btn1;
static String a = "";
public void button23(ActionEvent event) throws Exception{
a=lbl1.getText();
lbl2.setText(a);
Parent root = FXMLLoader.load(getClass().getResource("/application/2.fxml"));
//BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
Stage stage = new Stage();
stage.setScene(scene);
stage.show();
}
}
controller for second class
public class SecCon {
public Label lbl2;`enter code here`
public void labelDis(ActionEvent event){;
}
}