public void createWallLine(int y) { PositionButton button; Pane wallRec; for (int x = 0; x < 8; x++) { wallRec = new Pane(); wallRec.setPrefSize(30, 10); wallRec.setId("wallRec"); horizontalWalls[x][y] = wallRec; gameGrid.setConstraints(horizontalWalls[x][y], column, row); gameGrid.getChildren().add(horizontalWalls[x][y]); column++; button = new WallPositionButton(new Position(x, y)); button.setPrefSize(10, 10); button.setId("wallPosBtn"); wallPositionButtons[x][y] = button; gameGrid.setConstraints(wallPositionButtons[x][y], column, row); gameGrid.getChildren().addAll(wallPositionButtons[x][y]); column++; } wallRec = new Pane(); wallRec.setPrefSize(30, 10); wallRec.setId("wallRec"); horizontalWalls[8][y] = wallRec; gameGrid.setConstraints(horizontalWalls[8][y], column, row); gameGrid.getChildren().add(horizontalWalls[8][y]); column = 0; row++; }
public void createMoveLine(int y) { PositionButton button; Pane wallRec; button = new PlayerPositionButton(new Position(0, y)); button.setPrefSize(60, 60); button.setId("board"); playerPositionButtons[0][y] = button; gameGrid.setConstraints(button, column, row); gameGrid.getChildren().addAll(playerPositionButtons[0][y]); for (int x = 1; x < 9; x++) { column++; wallRec = new Pane(); wallRec.setPrefSize(10, 30); wallRec.setId("wallRec"); verticalWalls[x][y] = wallRec; gameGrid.setConstraints(wallRec, column, row); gameGrid.getChildren().add(verticalWalls[x][y]); column++; button = new PlayerPositionButton(new Position(x, y)); button.setPrefSize(60, 60); button.setId("board"); playerPositionButtons[x][y] = button; gameGrid.setConstraints(button, column, row); gameGrid.getChildren().addAll(playerPositionButtons[x][y]); } column = 0; row++; }
public GridPaneSample() { VBox vbox = new VBox(); // grid1 places the child by specifying the rows and columns in // GridPane.setContraints() Label grid1Caption = new Label( "The example below shows GridPane content placement by specifying rows and columns:"); grid1Caption.setWrapText(true); GridPane grid1 = new GridPane(); grid1.setHgap(4); grid1.setVgap(6); grid1.setPadding(new Insets(18, 18, 18, 18)); ObservableList<Node> content = grid1.getChildren(); Label label = new Label("Name:"); GridPane.setConstraints(label, 0, 0); GridPane.setHalignment(label, HPos.RIGHT); content.add(label); label = new Label("John Q. Public"); GridPane.setConstraints(label, 1, 0, 2, 1); GridPane.setHalignment(label, HPos.LEFT); content.add(label); label = new Label("Address:"); GridPane.setConstraints(label, 0, 1); GridPane.setHalignment(label, HPos.RIGHT); content.add(label); label = new Label("12345 Main Street, Some City, CA"); GridPane.setConstraints(label, 1, 1, 5, 1); GridPane.setHalignment(label, HPos.LEFT); content.add(label); vbox.getChildren().addAll(grid1Caption, grid1, new Separator()); // grid2 places the child by influencing the rows and columns themselves // via GridRowInfo and GridColumnInfo. This grid uses the preferred // width/height and max/min width/height. Label grid2Caption = new Label( "The example below shows GridPane content placement by influencing the rows and columns themselves."); grid2Caption.setWrapText(true); grid2Caption.setWrapText(true); GridPane grid2 = new GridPane(); grid2.setPadding(new Insets(18, 18, 18, 18)); RowConstraints rowinfo = new RowConstraints(40, 40, 40); ColumnConstraints colinfo = new ColumnConstraints(90, 90, 90); for (int i = 0; i <= 2; i++) { grid2.getRowConstraints().add(rowinfo); } for (int j = 0; j <= 2; j++) { grid2.getColumnConstraints().add(colinfo); } Label category = new Label("Category:"); GridPane.setHalignment(category, HPos.RIGHT); Label categoryValue = new Label("Wines"); Label company = new Label("Company:"); GridPane.setHalignment(company, HPos.RIGHT); Label companyValue = new Label("Acme Winery"); Label rating = new Label("Rating:"); GridPane.setHalignment(rating, HPos.RIGHT); Label ratingValue = new Label("Excellent"); ImageView imageView = new ImageView(ICON_48); GridPane.setHalignment(imageView, HPos.CENTER); // Place content GridPane.setConstraints(category, 0, 0); GridPane.setConstraints(categoryValue, 1, 0); GridPane.setConstraints(company, 0, 1); GridPane.setConstraints(companyValue, 1, 1); GridPane.setConstraints(imageView, 2, 1); GridPane.setConstraints(rating, 0, 2); GridPane.setConstraints(ratingValue, 1, 2); grid2 .getChildren() .addAll(category, categoryValue, company, companyValue, imageView, rating, ratingValue); vbox.getChildren().addAll(grid2Caption, grid2, new Separator()); // grid3 places the child by influencing the rows and columns // via GridRowInfo and GridColumnInfo. This grid uses the percentages Label grid3Caption = new Label( "The example below shows GridPane content placement by influencing row and column percentages. Also, grid lines are made visible in this example. The lines can be helpful in debugging."); grid3Caption.setWrapText(true); GridPane grid3 = new GridPane(); grid3.setPadding(new Insets(18, 18, 18, 18)); grid3.setGridLinesVisible(true); RowConstraints rowinfo3 = new RowConstraints(); rowinfo3.setPercentHeight(50); ColumnConstraints colInfo2 = new ColumnConstraints(); colInfo2.setPercentWidth(25); ColumnConstraints colInfo3 = new ColumnConstraints(); colInfo3.setPercentWidth(50); grid3.getRowConstraints().add(rowinfo3); // 2*50 percent grid3.getRowConstraints().add(rowinfo3); grid3.getColumnConstraints().add(colInfo2); // 25 percent grid3.getColumnConstraints().add(colInfo3); // 50 percent grid3.getColumnConstraints().add(colInfo2); // 25 percent Label condLabel = new Label(" Member Name:"); GridPane.setHalignment(condLabel, HPos.RIGHT); GridPane.setConstraints(condLabel, 0, 0); Label condValue = new Label("MyName"); GridPane.setMargin(condValue, new Insets(0, 0, 0, 10)); GridPane.setConstraints(condValue, 1, 0); Label acctLabel = new Label("Member Number:"); GridPane.setHalignment(acctLabel, HPos.RIGHT); GridPane.setConstraints(acctLabel, 0, 1); TextField textBox = new TextField("Your number"); GridPane.setMargin(textBox, new Insets(10, 10, 10, 10)); GridPane.setConstraints(textBox, 1, 1); Button button = new Button("Help"); GridPane.setConstraints(button, 2, 1); GridPane.setMargin(button, new Insets(10, 10, 10, 10)); GridPane.setHalignment(button, HPos.CENTER); GridPane.setConstraints(condValue, 1, 0); grid3.getChildren().addAll(condLabel, condValue, button, acctLabel, textBox); vbox.getChildren().addAll(grid3Caption, grid3); getChildren().add(vbox); }
/** * Here is our whole stage with layout, </Br > ( Grid, TextField and Buttons) * * @author PatrikWebb */ public void NameDisplay() { Stage nameWindow = new Stage(); // Block events to other windows nameWindow.initModality(Modality.APPLICATION_MODAL); nameWindow.setTitle("Enter your name"); nameWindow.setMinWidth(250); // GridPane Form GridPane grid = new GridPane(); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(8); grid.setHgap(10); // Name Label Label nameLabel = new Label("Player Name:"); GridPane.setConstraints(nameLabel, 0, 0); // Name Input nameInput = new TextField(); nameInput.setPromptText("Name"); nameInput.setFocusTraversable(false); GridPane.setConstraints(nameInput, 1, 0); // Betting Label Label bettingLabel = new Label("Betting amount: "); GridPane.setConstraints(bettingLabel, 0, 1); // Bett Input playerCashInput = new TextField(); playerCashInput.setFocusTraversable(false); playerCashInput.setPromptText("Betting amount"); GridPane.setConstraints(playerCashInput, 1, 1); // Enter button Button enterButton = new Button("Enter"); enterButton.setFocusTraversable(false); // setPercentWidth(50); GridPane.setConstraints(enterButton, 1, 2); // Cancel button Button cancelButton = new Button("Demo Player"); cancelButton.setFocusTraversable(false); GridPane.setConstraints(cancelButton, 2, 2); // enterButton.setOnAction( e -> { Platform.runLater( () -> { // Get the input from the nameInput TextField name = nameInput.getText(); // Get the betting input from the bettsInput TextField playerCash = Integer.parseInt(playerCashInput.getText()); // Add name and playerCash input to a new player Bank.getInstance().addPlayerToBank(name, playerCash); // Add the player to the table Bank.getInstance().addPlayersToTheTable(); // Close the stage nameWindow.close(); System.out.println("\nPlayer Name: " + name); System.out.println("Betting Amount: " + playerCash + "\n"); }); }); cancelButton.setOnAction( e -> { // TODO Platform.runLater( () -> { /* * * * * * * * * * * * * * If you press cancel you still want a player to join * the table so I add a test player insted of * getting the error, Exception JavaFX Application THREAD ;) * * * * * * * * * * * * */ Bank.getInstance().addPlayerToBank("Demo Player", 500); // Add the player to the table Bank.getInstance().addPlayersToTheTable(); nameWindow.close(); }); }); // Add everything to grid grid.getChildren() .addAll(nameLabel, nameInput, bettingLabel, playerCashInput, enterButton, cancelButton); // Display window and wait for it to be closed before returning Scene scene = new Scene(grid, 450, 150); nameWindow.setScene(scene); nameWindow.showAndWait(); }