I want to create a separate scene using the gridpane layout. I have tried basically copying all the code and creating a new scene, but everything i put in the 2nd scene doesn't snap to the grid. I'm fairly new to coding, and this is my 5th project. (so sorry for the bad code)
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class Main extends Application {
Stage window;
Scene s1, s2;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("Test");
GridPane grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
grid.setVgap(10);
grid.setHgap(10);
Button b1 = new Button("Scene 2");
b1.setOnAction(e -> window.setScene(s2));
GridPane.setConstraints(b1, 2, 0);
Button b2 = new Button("Button 2");
GridPane.setConstraints(b2, 5, 0);
grid.getChildren().addAll(b1, b2);
Scene s1 = new Scene(grid, 500, 500);
GridPane grid2 = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
grid.setVgap(10);
grid.setHgap(10);
Button b3 = new Button("Scene 1");
b3.setOnAction(e -> window.setScene(s1));
GridPane.setConstraints(b3, 0, 0);
Button b4 = new Button("Button 2");
GridPane.setConstraints(b4, 6, 0);
grid2.getChildren().addAll(b3, b4);
s2 = new Scene(grid2, 500, 500);
window.setScene(s1);
window.show();
}
}
grid2
. – James_D Dec 18 '17 at 2:21