2017-08-16 32 views
0

我有一個TextField和帶有mnemonicParsing true的標籤。我想用TextField的id設置標籤的labelFor屬性。我如何在FXML中做到這一點?JavaFx:如何在FXML中設置label的labelFor屬性?

<GridPane hgap="5.0" snapToPixel="false" vgap="10.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> 
<children> 
     <Label maxWidth="-Infinity" text="_A Label" GridPane.halignment="RIGHT" GridPane.hgrow="NEVER" GridPane.vgrow="NEVER" mnemonicParsing="true" /> 
     <TextField id="myTextField" GridPane.columnIndex="1" GridPane.hgrow="NEVER" /> 
</children> 
</GridPane> 

感謝

回答

0

如果找到了解決辦法...

<GridPane hgap="5.0" snapToPixel="false" vgap="10.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> 
<children> 
     <Label maxWidth="-Infinity" text="_A Label" GridPane.halignment="RIGHT" GridPane.hgrow="NEVER" GridPane.vgrow="NEVER" mnemonicParsing="true"> 
      <labelFor> 
       <TextField id="myTextField" GridPane.columnIndex="1" GridPane.hgrow="NEVER" /> 
      </labelFor> 
     </Label> 
     <fx:reference source="myTextField" /> 
</children> 
</GridPane> 
0

您可以使用美元符號:

<GridPane hgap="5.0" snapToPixel="false" vgap="10.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
      <Label labelFor="$myTextField" maxWidth="-Infinity" text="_A Label" GridPane.halignment="RIGHT" GridPane.hgrow="NEVER" GridPane.vgrow="NEVER" mnemonicParsing="true" /> 
      <TextField id="myTextField" GridPane.columnIndex="1" GridPane.hgrow="NEVER" /> 
    </children> 
</GridPane> 
相關問題