fxml - JavaFX Data Mangement -
this question has answer here:
- passing parameters javafx fxml 6 answers
- access fields controller in javafx 2 answers
scene 1 scene1controller! has text field (customer name) , button!
when click button in scene 1, on-screen keyboard appear without closing scene!
on-screen keyboard has has own controller!
on-screen keyboard has textfield , complete keyboard
typed "stackoverflow" textfield of on-screen keyboard!
after pressing enter in on-screen keyboard how retrieve textfield value of on-screen keyboard 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 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 written text field of on-screen keyboard textfield of scene 1 }
just create property in keyboard controller represent text, , observe "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 keyboard) ; } // ... else 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 newvalue: customername.settext(newvalue); } }); // show keyboard ... } // other code... }
Comments
Post a Comment