document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import javafx.application.Application;
  2. import javafx.scene.Scene;
  3. import javafx.scene.control.Button;
  4. import javafx.scene.layout.GridPane;
  5. import javafx.stage.Stage;
  6.  
  7. /**
  8. *
  9. * @web http://zoranpavlovic.blogspot.com/
  10. */
  11. public class GridPaneMain extends Application {
  12.  
  13. /**
  14. * @param args the command line arguments
  15. */
  16. public static void main(String[] args) {
  17. launch(args);
  18. }
  19.  
  20. @Override
  21. public void start(Stage primaryStage) {
  22. primaryStage.setTitle("GridPane example");
  23.  
  24. //Adding GridPane
  25. GridPane gridPane = new GridPane();
  26.  
  27. // 2D array of Buttons with value of 5,5
  28. Button[][] btn = new Button[5][5];
  29.  
  30. //Column is a vertical line and row is a horizontal line
  31. //Two FOR loops used for creating 2D array of buttons with values i,j
  32. for(int i=0; i<btn.length; i++){
  33. for(int j=0; j<btn.length;j++){
  34.  
  35. //Initializing 2D buttons with values i,j
  36. btn[i][j] = new Button(""+i+","+""+j);
  37. btn[i][j].setPrefSize(50, 50);
  38. gridPane.add(btn[i][j], i, j);
  39. }
  40. }
  41.  
  42. //Adding GridPane to the scene
  43. Scene scene = new Scene(gridPane);
  44. primaryStage.setScene(scene);
  45. primaryStage.show();
  46. }
  47. }
');