0

Elaborating my question further, I am developing a question bank in JavaFX. At the home screen, I wish to provide navigation based on radiobutton choice inside a button click.

e.g. If I select a radiobutton choice, and click on the button to proceed ahead, it should direct me to the FXML screen file I have created. To further explain what I am trying to stay, below is the GUI snapshot.

Question Bank GUI Link

I am pasting my code below :

Main HomeScreen FXML File :

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

<?import java.lang.*?>


<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<AnchorPane id="AnchorPane" prefHeight="548.0" prefWidth="721.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="controller.HomefxmlController">
  <children>
    <GridPane alignment="CENTER" gridLinesVisible="false" layoutX="210.0" layoutY="149.0" prefHeight="171.0" prefWidth="373.0" visible="true">
      <children>
        <RadioButton fx:id="radioBlanks" alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" onAction="#onRadioBlankClick" text="Fill in the Blank" GridPane.columnIndex="0" GridPane.halignment="LEFT" GridPane.rowIndex="0" GridPane.valignment="CENTER" />
        <RadioButton fx:id="radioMcq" mnemonicParsing="false" onAction="#onRadioMcqClick" text="MCQ" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="0" />
        <RadioButton fx:id="radioshortNote" alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" onAction="#onRadioSNclick" text="ShortNote" GridPane.columnIndex="0" GridPane.halignment="LEFT" GridPane.rowIndex="1" />
        <RadioButton fx:id="radioLongAnswer" mnemonicParsing="false" onAction="#onRadioLNclick" text="LongAnswer" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="1" />
        <RadioButton fx:id="radioScenario" mnemonicParsing="false" onAction="#onRadioScenariocClick" text="Scenario" GridPane.columnIndex="0" GridPane.halignment="LEFT" GridPane.rowIndex="2" />
        <RadioButton fx:id="radioTF" mnemonicParsing="false" onAction="#onRadioTFclick" text="True/False" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="2" />
      </children>
      <columnConstraints>
        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
      </columnConstraints>
      <rowConstraints>
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
      </rowConstraints>
    </GridPane>
    <Label alignment="CENTER" layoutX="234.0" layoutY="47.0" prefHeight="73.0" prefWidth="211.0" text="Question Bank" textAlignment="CENTER" underline="true" wrapText="false">
      <font>
        <Font name="Chiller" size="35.0" />
      </font>
    </Label>
    <Button fx:id="btnProceed" layoutX="275.0" layoutY="378.0" mnemonicParsing="false" onAction="#onBtntProceed" prefHeight="48.0" prefWidth="129.0" text="Proceed" textFill="#252285">
      <font>
        <Font name="Linux Libertine G Regular" size="20.0" />
      </font>
    </Button>
  </children>
  <stylesheets>
    <URL value="@homefxml.css" />
  </stylesheets>
</AnchorPane>

FXML Controller File :

package controller;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 * @author Vishal
 */
public class HomefxmlController implements Initializable {

    @FXML
    private RadioButton radioBlanks;
    @FXML
    private RadioButton radioMcq;
    @FXML
    private RadioButton radioshortNote;
    @FXML
    private RadioButton radioLongAnswer;
    @FXML
    private RadioButton radioScenario;
    @FXML
    private RadioButton radioTF;
    @FXML
    private Button btnProceed;

    ToggleGroup group;

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        toggleGroupAssign();

    }

    public void toggleGroupAssign() {
        group = new ToggleGroup();
        radioBlanks.setToggleGroup(group);
        radioMcq.setToggleGroup(group);
        radioshortNote.setToggleGroup(group);
        radioLongAnswer.setToggleGroup(group);
        radioScenario.setToggleGroup(group);
        radioTF.setToggleGroup(group);
    }

    @FXML
    private void onBtntProceed(ActionEvent event) throws IOException {
         // I am selecting just one checkbox at the moment for testing purpose..
         if(radioTF.isSelected()){
             FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/tester.fxml"));     
             loader.load();
         } 
    }

}

The PROBLEM is that NO ERROR appears at all. No compiletime error, no runtime, nothing ! It just doesn't work !

Kindly help me where exactly I am going wrong ?

Vishal A
  • 144
  • 3
  • 17

1 Answers1

1

loader.load() returns a Node, you don't assign

Take a look at this link Loading new fxml in the same scene

Community
  • 1
  • 1
Manuel Seiche
  • 231
  • 1
  • 5
  • Thanks for the hint. The quick fix provided at the link didn't exactly solve my problem, but a little adjustment with anchorpane did that : content.getChildren().clear(); content.getChildren().add(FXMLLoader.load(getClass().getResource("/package/filename.fxml"))); Added these two lines, and it was done ! – Vishal A Mar 21 '16 at 12:05