2

I have two screens which will be loaded at the start of program. I have a text field and a button on screen 1 and a label on screen2.

Now when I enter any text in text field of screen1 and and press the button, the label on screen2 should be set to that text (which was entered in screen1). (both the screens are active all the time right from program launch, so we need to update the label after the FXML is loaded).

I have tried properties and binding but had no success.

Controller 1: (Mapped to Controller1.fxml)

public class Controller1 {
@FXML private Button button;
@FXML private TextField tfield;
}

Controller 2: (Mapped to Controller2.fxml)

public class Controller2 {
@FXML private Label label;
}

Both the stages/screens are created from MainDriver.java class.

SuperStar
  • 57
  • 2
  • 12
  • possible duplicate of [Passing Parameters JavaFX FXML](http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml) – ItachiUchiha Jul 10 '14 at 05:57
  • Nope, its not! In the link that you provided, user will invoke a new window from the existing. In my scenario both the windows are loaded at the program start. This is making it challenging, and hence I have emphasized on this point in my query. – SuperStar Jul 10 '14 at 13:48
  • 1
    Try http://stackoverflow.com/q/12166786/1759128. The Link I posted above eventually has a link to this as well ! – ItachiUchiha Jul 10 '14 at 14:19
  • Looks like you still din't my constrain!! In simple words, I need to modify the data (Label) of a COMPLETED LOADED FXML with data from another COMPLETED LOADED FXML. – SuperStar Jul 10 '14 at 16:16
  • Show the bindings you tried, that's what I'd do. Make sure you load the controllers [like in this answer](http://stackoverflow.com/a/21996083/2855515) – brian Jul 10 '14 at 22:15
  • What do you mean by "screen"? A Stage or a Pane or something else? Did you have make sure that *button*, *tfield* and *label* are `!= null`? With binding it would update *label* every pressed key in *tfield*, but you want to update after clicking *button*. So it must look like `screen1.button.setOnAction(e -> screen2.label.setText(screen1.tfield.getText()));` – Vertex Jul 10 '14 at 22:43
  • I have the exact issue. Did you find the solution to this ? Could you please post it ASAP. Thanks – shahakshay94 Jun 08 '18 at 21:02

0 Answers0