1
votes

1) When I run it, all the objects placed in the TOP_CENTER as you can see in the code I tried to place the button in the BOTTOM_RIGHT and it didn't work.

2) Can a Scene include two layouts? (Two VBox-es for example).

public void NewQuestion ()
{
    sum++;
    t=new Text("Question number: "+sum);

    textfield=new TextField();
    pane = new VBox();

    Button NextQuestion = new Button ("Next Question");
    NextQuestion.setOnAction(e-> NextQuestionButtonClicked(e));
    pane.getChildren().addAll(t, textfield, NextQuestion);
    pane.setAlignment(Pos.TOP_CENTER);
    NextQuestion.setAlignment(Pos.BOTTOM_RIGHT);//<---


    Scene mainscene = new Scene(pane,420, 530);


    Qstage.setScene(mainscene);


}
2

2 Answers

3
votes

Answering your second question first : each layout is a node so you can make a Hbox and then add 2 Vboxs to it and in a similar fashion have all combinations of it. since each button is also a node, you can add a Vbox and a button to an Hbox to position them horizontally with respect to each other

Now back to your first question: Here is a list and an example with Pos.CENTER and Pos.CENTER_LEFT : enter image description here

Hope this helps. Feel free to ask any more questions about this

2
votes

1) button.setAlignment sets how the text and icons are places inside the button (javadoc). To align the button within a pane you should apply desired alignment to the pane itself. In you case:

pane.setAlignment(Pos.BOTTOM_RIGHT);

instead of

pane.setAlignment(Pos.TOP_CENTER);

2) The Scene should have a single root. But the root itself may be a VBox or HBox and you could put multiple boxes inside other box.