Skip to content

Instantly share code, notes, and snippets.

@ahinchman1
Created May 23, 2018 03:46
Show Gist options
  • Save ahinchman1/db53e82adee1399219a6aaa3223e1617 to your computer and use it in GitHub Desktop.
Save ahinchman1/db53e82adee1399219a6aaa3223e1617 to your computer and use it in GitHub Desktop.
JavaFX GridPane example
class GridPaneExample {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
int numCol = 8;
GridPane pane = new GridPane();
pane.setVgap(15);
pane.setPadding(new Insets(15, 15, 15, 15));
// one row
for (int i = 0; i < numCol; i++) {
pane.add(horizontalStreetPane());
}
// show scene
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
}
public StackPane horizontalStreetPane() {
Rectangle grass = new Rectangle(100.0, 100.0);
grass.setFill(Color.GREEN);
StackPane stack = new StackPane(grass);
Rectangle street = new Rectangle(100.0, 40.0);
street.setFill(Color.GRAY);
// adding additional elements overlays elements
stack.getChildren().add(street);
return stack;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment