Question: Java with SceneBuilder 2.0: I'm using Scene Builder 2.0 to create a Java FXML. I'm using radio buttons, but for some reason I can't get
Java with SceneBuilder 2.0:
I'm using Scene Builder 2.0 to create a Java FXML. I'm using radio buttons, but for some reason I can't get the radio button selection to change the label I want. All I'm trying to do at this point is tie the buttons to a label text change. I do have the radio buttons tied to a toggle group called group in the Sample.fxml tab. The label I'm trying to change the text of is the lblOutputLabel.
Sample.fxml tab
xml version="1.0" encoding="UTF-8"?> import javafx.geometry.*?> import javafx.scene.text.*?> import javafx.scene.control.*?> import java.lang.*?> import javafx.scene.layout.*?> import javafx.geometry.Insets?> import javafx.scene.layout.GridPane?> import javafx.scene.control.Button?> import javafx.scene.control.Label?> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="486.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <children> <RadioButton fx:id="rbDectoBin" layoutX="39.0" layoutY="260.0" mnemonicParsing="false" text="Decimal to Binary"> <toggleGroup> <ToggleGroup fx:id="group" /> toggleGroup>RadioButton> <RadioButton fx:id="rbDectoHex" layoutX="39.0" layoutY="291.0" mnemonicParsing="false" text="Decimal to Hex" toggleGroup="$group" /> <RadioButton fx:id="rbBintoDec" layoutX="39.0" layoutY="322.0" mnemonicParsing="false" text="Binary to Decimal" toggleGroup="$group" /> <HBox alignment="CENTER" layoutX="8.0" layoutY="14.0" prefHeight="100.0" prefWidth="685.0" style="-fx-background-color: gray;"> <children> <Label alignment="CENTER" contentDisplay="CENTER" text="Decimal Conversion" /> children> <padding> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> padding> HBox> <Label layoutX="39.0" layoutY="156.0" text="Enter an appropriate value for conversion" wrapText="true" /> <TextField layoutX="36.0" layoutY="201.0" /> <Label fx:id="lblOuputLabel" layoutX="467.0" layoutY="270.0" /> <RadioButton fx:id="rbHextoDec" layoutX="39.0" layoutY="353.0" mnemonicParsing="false" text="Hex to Decimal" toggleGroup="$group" /> children> AnchorPane>
Controller
package sample; import javafx.fxml.FXML; import javafx.scene.control.*; public class Controller { @FXML RadioButton rbDectoBin; @FXML RadioButton rbDectoHex; @FXML RadioButton rbBintoHex; @FXML RadioButton rbHextoDec; @FXML Label lblOutputLabel; public void radioButtonChanged() { if (rbDectoBin.isSelected()) { lblOutputLabel.setText("Boo"); } if (rbDectoHex.isSelected()) { lblOutputLabel.setText("Thanksgiving"); } if (rbHextoDec.isSelected()) { lblOutputLabel.setText("Christmas"); } if (rbBintoHex.isArmed()) { lblOutputLabel.setText("Snow"); } } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
