3 Replies Latest reply: Jul 27, 2013 3:39 PM by user597585 RSS

    labelFor

    user597585

      How do you get the labelFor attribute in FXML to work? 

       

      I'm new to JavaFX.... I'm using the latest jdk 8 ea

       

      I though if I set the labelFor attribute to the component's id that it would work..

       

      No luck.  The exception is:  Unable to coerce opacitySlider to class javafx.scene.Node.

       

      Any help would be appreciated,

       

      thanks,

       

      John

       

       

      This is my sample layout:

       

      <?xml version="1.0" encoding="UTF-8"?>

       

      <?import java.lang.*?>

      <?import javafx.geometry.Insets?>

      <?import javafx.scene.control.*?>

      <?import javafx.scene.control.Button?>

      <?import javafx.scene.control.Label?>

      <?import javafx.scene.layout.*?>

      <?import javafx.scene.layout.GridPane?>

      <?import javafx.scene.web.*?>

       

      <GridPane alignment="CENTER" hgap="10.0" mouseTransparent="false" vgap="10.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">

        <children>

          <Slider id="opacitySlider" orientation="HORIZONTAL" GridPane.columnIndex="2" GridPane.rowIndex="1" />

          <Label id="opacityLabel" mnemonicParsing="true" text="_Opacity" GridPane.columnIndex="1" GridPane.rowIndex="1" labelFor="opacitySlider"/>

          <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />

          <TextField id="txtField" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="2" />

        </children>

        <columnConstraints>

          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />

          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />

          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />

        </columnConstraints>

        <rowConstraints>

          <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />

          <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />

          <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />

          <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />

        </rowConstraints>

      </GridPane>