getting text from textfield java fxml -
here fxml code , java controller file code. trying text textfield tf in handle event using "string s = tf.gettext().tostring();" not getting executed.
<?xml version="1.0" encoding="utf-8"?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.anchorpane?> <anchorpane fx:id = "apane" prefheight="268.0" prefwidth="379.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="sample.searchcontroller"> <children> <vbox layoutx="20.0" layouty="36.0" prefheight="232.0" prefwidth="333.0"> <children> <hbox prefheight="36.0" prefwidth="333.0"> <children> <label fx:id= "kw" text="key word : "> <padding> <insets right="10.0" /> </padding> </label> <textfield fx:id="tf" prefheight="25.0" prefwidth="120.0" /> <button fx:id="srch" mnemonicparsing="false" onaction="#handle" text="search" > <hbox.margin> <insets left="10.0" /> </hbox.margin> </button> </children> <padding> <insets left="6.0" top="6.0" /> </padding> <vbox.margin> <insets /> </vbox.margin> <opaqueinsets> <insets /> </opaqueinsets> </hbox> <textarea fx:id="ta" prefheight="174.0" prefwidth="282.0" /> </children> </vbox> </children> </anchorpane>
java controller code :
public class searchcontroller implements initializable,eventhandler<actionevent> { anchorpane apane = new anchorpane(); label kw = new label(); public textfield tf; button srch = new button(); textarea ta = new textarea(); //text t; string s = "priyam"; @override public void initialize(url location, resourcebundle resources) { // todo auto-generated method stub tf = new textfield(); } @override public void handle(actionevent arg0) { // todo auto-generated method stub s=tf.gettext().tostring(); system.out.println(s); } }
the method initialize()
overrides value of tf
. initialize textfield
object tf
new object.
@override public void initialize(url location, resourcebundle resources) { // todo auto-generated method stub tf = new textfield(); }
Comments
Post a Comment