Reputation: 582
<Label fx:id="lblLibrarianId" layoutX="82.0" layoutY="14.0" prefHeight="24.0" prefWidth="212.0" text="$librarianId" />
I have a controller name LibraryController
. I set label value text to librarianId
dynamically from another controller. Now, I want to access this librarianId
to LibraryController
.
final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../fxmlfile/librarian.fxml"));
fxmlLoader.getNamespace().put("librarianId", librarianId);
This is the way how I set the value dynamically to Label text field
. Now I want to retrieve that Label Text value
to my LibraryController
.
Upvotes: 0
Views: 3679
Reputation: 109
In your controller, create your label object, and call getText() you'll need to use the @FXML to associate that object with the fx:id in your .fxml file
ex.
public class LibraryController{
@FXML public Label lblLibrarianId;
public String librarianID;
final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../fxmlfile/librarian.fxml"));
fxmlLoader.getNamespace().put("librarianId", librarianId);
librarianId = lblLibrarianId.getText();
}
Upvotes: 1