0

Am trying to load a new scene from another class into the main javafx page and this is the main javafx page

    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.layout.GridPane;
    import javafx.scene.control.Button;
    import javafx.scene.control.Hyperlink;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextField;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.FlowPane;
    import javafx.scene.layout.HBox;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;

    public class Cbt extends Application {
      Stage stageCbt;
      Scene staffMainPage;
      BorderPane border;
      FlowPane addFlowPane;
      Hyperlink SQuestions, setParameters;

      public void start(Stage theMainStage){

            stageCbt = theMainStage;

            border = new BorderPane();

            SQuestions.setOnAction(ae -> createQuestionsLinkClicked(ae));
      }
      private FlowPane addFlowPaneLO() {

            addFlowPane = new FlowPane();
            addFlowPane.getStyleClass().addAll("pane", "vbox");

            Hyperlink options[] = new Hyperlink[]{
                setParameters = new Hyperlink("set Questions Parameters"),
                SQuestions = new Hyperlink("Select past jamb questions")
            };

            for (int i = 0; i < 2; i++) {
                addFlowPane.setMargin(options[i], new Insets(0, 0, 0, 8));
                addFlowPane.getChildren().add(options[i]);
            }
            addFlowPane.getStyleClass().addAll("pane", "flow");
            addFlowPane.setPrefWrapLength(170);

            return addFlowPane;
         }

         public void createQuestionsLinkClicked(ActionEvent ae) {
        if (ae.getSource() == SQuestions) {
            //Questions ques = new Questions();
            stageCbt.setScene(staffMainPage);
            borderpane.setCenter(new Questions().getAnchor());
        }
    }


         public static void main(String[] args) {
            launch(args);
         }

}

and this is the the subclass(Questions.java)

import javafx.beans.property.StringProperty;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ListView;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextArea;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;


public class Questions {
    TextArea putQues;
    Button end, edit, review, next;
    BorderPane bpane;
    GridPane gdQues;
    AnchorPane anchor;
    ToggleGroup oneSelected;
    Text msg, option;

    public static String lvo[] = new String[]{
        "Option A", 
        "Option B",
        "Option C",
        "Option D",
        "Option E"
    };

    public static String rbo[] = new String[]{
        "A",
        "B",
        "C",
        "D",
        "E"
    };

    RadioButton rbs[] = new RadioButton[rbo.length];
    ListView lvs [] = new ListView[lvo.length];

    public Questions(){
       gdQues = new GridPane();
       gdQues.setHgap(10);
       gdQues.setVgap(10);;
       gdQues.setAlignment(Pos.TOP_LEFT);
       gdQues.getStyleClass().add("grid");

       msg = new Text("Questions should be put below");
       msg.setFont(Font.font("Arial", FontWeight.BOLD, 20));
       gdQues.add(msg, 3, 3);

       putQues = new TextArea();
       putQues.setPromptText("Type question here"); 
       gdQues.add(putQues, 4, 0);

       option = new Text("Options");
       option.setFont(Font.font("Monotype Corsiva", FontWeight.BOLD, 10));
       gdQues.add(option, 6, 0);

       //options = new ListView();
       //ListView optionAll = new ListView();
       for(int i = 0; i < rbo.length; i++){
           RadioButton rb = rbs[i] = new RadioButton(rbo[i]);
           ListView lv = lvs[i];
           rbs[i].setToggleGroup(oneSelected);
       }
       //gdQues.getChildren().addAll(rbs);
       //gdQues.getChildren().addAll(lvs);

       anchor = new AnchorPane();
       anchor.getStyleClass().add("pane");

       end = new Button("End");
       edit = new Button("Edit");
       review = new Button("Review");
       next = new Button("Next");

       HBox hb = new HBox();
       hb.getStyleClass().add("hb");
       hb.getChildren().addAll(end, edit, review, next);
       anchor.getChildren().addAll(gdQues, hb);

    }
    public Parent getGdQues(){
       return gdQues; 
    }
    public Parent getAnchor(/*GridPane gdQues*/){
        return anchor;
    }
    public Parent getPutQues(){
        return putQues;
    }
    public Text getMsg(){
        return msg;
    }
    /*public Parent  getRbs(){
        return rbo;
    }
    public Parent getLvs(){
        return lvs;
    }*/
}

all other controls display except the radiobuttons(of which I guess is because the function wasn't move into the constructor).

My question now is how get the radiobuttons to display?

1 Answers1

0

I do not know the format your are using while in instantiating your radio button, see:

RadioButton rb = rbs[i] = new RadioButton(rbo[i]);

See also this question: initialize multiple variables in a same line in java

Maybe are the instantiation in the other oder as you think done. Or you simply forget to delete the fisrt part. Whatever, it seams, you do not use the rb variable, so prefer:

rbs[i] = new RadioButton(rbo[i]);

Or separate it into 2 lines.

Community
  • 1
  • 1
Loic Mouchard
  • 1,121
  • 7
  • 22