if node having fx:id (say a) normal id(css id) (say b). if lookup used search node:
node node=scene.lookup("#a")
the above statement returns null. if there no css id corresponding node in discussion, above statement returns correct node.
while using below given statement returns correct result:
node node=scene.lookup("#b")
can please explain why lookup method behaving weirdly?
<?xml version="1.0" encoding="utf-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.image.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.text.*?> <gridpane hgap="14.0" maxheight="+infinity" maxwidth="+infinity" minheight="-infinity" minwidth="-infinity" prefheight="223.0" prefwidth="323.0" vgap="20.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <children> <vbox maxheight="+infinity" maxwidth="+infinity" minheight="-infinity" spacing="7.0" gridpane.rowindex="0"> <children> <hbox alignment="top_right"> <children> <label fx:id="headermessage" text="message" textalignment="left" wraptext="true"> <font> <font name="system bold" size="13.0" /> </font> </label> </children> </hbox> <hbox alignment="top_right" spacing="5.0"> <children> <label fx:id="qty" text="details" textalignment="left" wraptext="true"> <font> <font size="12.0" /> </font> </label> <textfield fx:id="qtyt" /> </children> </hbox> <hbox alignment="top_right" spacing="5.0"> <children> <label fx:id="name" text="details" textalignment="left" wraptext="true"> <font> <font size="12.0" /> </font> </label> <textfield fx:id="namet" /> </children> </hbox> <hbox alignment="top_right" spacing="5.0"> <children> <label fx:id="remarks" text="details" textalignment="left" wraptext="true"> <font> <font size="12.0" /> </font> </label> <textarea fx:id="remarkst" prefheight="60.0" prefwidth="149.0" wraptext="true" /> </children> </hbox> </children> </vbox> <hbox maxheight="-infinity" maxwidth="+infinity" minheight="-infinity" minwidth="-infinity" prefheight="25.0" prefwidth="253.0" gridpane.rowindex="1"> <children> <pane maxwidth="+infinity" hbox.hgrow="always" /> <button id="cancel-button" fx:id="cancelbutton" cancelbutton="true" minwidth="80.0" mnemonicparsing="false" text="cancel" hbox.hgrow="never"> <hbox.margin> <insets /> </hbox.margin> </button> <hbox fx:id="okparent" alignment="center"> <children> <button id="ok-button" fx:id="okbutton" minwidth="80.0" mnemonicparsing="false" text="ok" hbox.hgrow="never"> <hbox.margin> <insets left="14.0" /> </hbox.margin> </button> </children> </hbox> </children> </hbox> </children> <columnconstraints> <columnconstraints halignment="center" hgrow="always" maxwidth="+infinity" minwidth="-infinity" /> </columnconstraints> <padding> <insets bottom="14.0" left="14.0" right="14.0" top="14.0" /> </padding> <rowconstraints> <rowconstraints maxheight="+infinity" minheight="-infinity" valignment="center" vgrow="always" /> <rowconstraints maxheight="-infinity" minheight="-infinity" vgrow="never" /> </rowconstraints> </gridpane> in above fxml, lookup works fine on fxml id's nodes don't have css id. if css id present, return nulls
label headermessage = (label) alertstage.getscene().lookup("#headermessage"); final textfield qty = (textfield) alertstage.getscene().lookup("#qtyt"); label name = (label) alertstage.getscene().lookup("#name"); final textarea remarkst = (textarea) alertstage.getscene().lookup("#remarkst"); final textfield namet = (textfield) alertstage.getscene().lookup("#namet"); lookup method fails given below statement.
button okbutton = (button) alertstage.getscene().lookup("#okbutton");
edit - after op added mcve
digging matter. got simple statement written deep inside documentation of fxml explains behaviour. actually, fx:id assigned default id of control / layout calling setid().
unless overridden, fx:id stays default id of object.
from introduction fxml :
assigning fx:id value element creates variable in document's namespace can later referred variable dereference attributes, such "togglegroup" attribute shown above, or in script code, discussed in later section. additionally, if object's type defines "id" property, value passed objects setid() method.
the lookup() doing job , working css selectors , not on fx:id.
Comments
Post a Comment