1

Scene 1 with its Scene1Controller! it has a text field (Customer Name) and a button!

When I click the button in scene 1, a on-screen keyboard will appear without closing the scene!

on-screen keyboard has it has its own controller!

on-screen keyboard has a textfield and complete keyboard

typed "stackoverflow" into the textfield of on-screen keyboard!

after pressing enter in the on-screen keyboard how do I retrieve the textfield value of the on-screen keyboard into the customer name field of scene 1?

SCENE 1:

<TextField fx:id="CustomerName" layoutX="14.0" layoutY="75.0" onAction="#TextBoxTextChanged" prefHeight="29.0" prefWidth="254.0"/>
<Button fx:id="OnScreenKeyBoardButton" layoutX="268.0" layoutY="75.0" mnemonicParsing="false" onAction="#ButtonNameClick" prefHeight="29.0" text="..." />

On-Screen Keyboard:

All the Key's and

Enter Button Code:

<Button fx:id="enterButton" layoutX="796.0" layoutY="210.0" minHeight="18.8" mnemonicParsing="false" prefHeight="40.0" prefWidth="90.0" text="Enter" onAction="#ButtonEnterClick"/>

Scene 1 Controller:

@FXML
public void ButtonNameClick(final ActionEvent event)
{
  //opens on-screen keyboard
}

On-Screen Keyboard Controller:

@FXML
public void ButtonEnterClick(final ActionEvent event)
{
  //code to be written to get the text field of the on-screen keyboard into the textfield of scene 1
}

1 Answers1

3

Just create a property in the keyboard controller to represent the text, and observe it from the "Screen1Controller":

public class KeyboardController {
    private StringProperty text = new SimpleStringProperty(this, "text", "");
    public StringProperty textProperty() {
         return text ;
    }
    public String getText() {
        return text.get();
    }
    public void setText(String text) {
        this.text.set(text);
    }

    @FXML
    public void buttonEnterClick(ActionEvent event) {
        text.set(// text from keyboard) ;
    }
    // ... everything else as before
}

And

public class Screen1Controller {
    @FXML
    private TextField customerName ;
    // ...
    @FXML
    public void buttonNameClick(ActionEvent event) {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("Keyboard.fxml"));
        Parent parent = loader.load();
        KeyboardController controller = (KeyboardContoller) loader.getController();
        controller.textProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> obs, String oldValue, String newValue) {
                // update text field with newValue:
                customerName.setText(newValue);
            }
        });
        // show keyboard ...
    }

    // other code...
}
James_D
  • 201,275
  • 16
  • 291
  • 322
  • Thank you for your elaborate answer but the On-Screen Keyboard will be launched only after the buttonNameClick complete its execution! you cannot modify the textfield of scene 1. if you know what I mean in that case – user3542583 Apr 16 '14 at 21:10
  • I don't really understand that comment. Did you try my code? The `textfield` in "scene 1" will be updated when the `buttonEnterClick(...)` method in the `KeyboardController` is executed. Is that not what you wanted? – James_D Apr 16 '14 at 21:42