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...


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




AnchorPanemaxHeight="-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>


RadioButtonfx:id="rbDectoBin" layoutX="39.0" layoutY="260.0" mnemonicParsing="false" text="Decimal to Binary">


toggleGroup>


ToggleGroupfx:id="group" />


toggleGroup>RadioButton>


RadioButtonfx:id="rbDectoHex" layoutX="39.0" layoutY="291.0" mnemonicParsing="false" text="Decimal to Hex" toggleGroup="$group" />


RadioButtonfx: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">


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" />


TextFieldlayoutX="36.0" layoutY="201.0" />


Label fx:id="lblOuputLabel" layoutX="467.0" layoutY="270.0" />


RadioButtonfx: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


RadioButtonrbDectoBin;



    @FXML


RadioButtonrbDectoHex;


    @FXML


RadioButtonrbBintoHex;


    @FXML


RadioButtonrbHextoDec;


    @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");


        }



    }


}



May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here