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);
  }
Пример #2
0
    public JavaFXJeopardyBoardViz(Object pane) {

      mainBoardPane = (StackPane) pane;
      mainBoardPane.getChildren().clear();

      // Create and add children of mainBoardPane
      gridPane = new GridPane();
      gridPane.setHgap(10);
      gridPane.setVgap(10);
      questionText = new Button("");
      mainBoardPane.getChildren().addAll(gridPane, questionText);

      gridPane.toString();

      questionText.setMaxWidth(Double.MAX_VALUE);
      questionText.setMaxHeight(Double.MAX_VALUE);
      questionText.setWrapText(true);
      questionText.setTextAlignment(TextAlignment.CENTER);
      questionText.setStyle(
          "-fx-text-fill: white; -fx-font-size: 36px; -fx-font-weight: bold; -fx-background-color: #0000FF;");
      questionText.setVisible(false);

      // Set the columns to be equal sizes in the grid
      for (int col = 1; col <= 6; col++) {
        ColumnConstraints colConstraint = new ColumnConstraints();
        colConstraint.setPercentWidth(100 / 6);
        gridPane.getColumnConstraints().add(colConstraint);
      }

      // Set the rows to be equal sizes in the grid
      RowConstraints rowConstraint = new RowConstraints();
      rowConstraint.setPercentHeight(12);
      gridPane.getRowConstraints().add(rowConstraint);
      for (int row = 1; row <= 5; row++) {
        rowConstraint = new RowConstraints();
        rowConstraint.setPercentHeight(88 / 5);
        gridPane.getRowConstraints().add(rowConstraint);
      }

      categoryButtons = new Button[6];

      itemButtons = new Button[5][6];

      // Add buttons for category titles
      for (int categoryIndex = 0; categoryIndex <= 5; categoryIndex++) {
        categoryButtons[categoryIndex] = new Button(categories.get(categoryIndex).getName());
        categoryButtons[categoryIndex].setMaxWidth(Double.MAX_VALUE);
        categoryButtons[categoryIndex].setMaxHeight(Double.MAX_VALUE);
        categoryButtons[categoryIndex].setWrapText(true);
        categoryButtons[categoryIndex].setTextAlignment(TextAlignment.CENTER);
        categoryButtons[categoryIndex].setStyle(
            "-fx-text-fill: white; -fx-font-size: 14px; -fx-font-weight: bold; -fx-background-color: #0000FF;");
        // categoryButtons[categoryIndex].setFont(new Font("Arial Narrow", 14px));
        gridPane.add(categoryButtons[categoryIndex], categoryIndex, 0);

        // Add buttons for BoardItems
        for (int itemIndex = 0; itemIndex <= 4; itemIndex++) {
          itemButtons[itemIndex][categoryIndex] =
              new JeopardyItemButton(categories.get(categoryIndex).getBoardItem(itemIndex));
          itemButtons[itemIndex][categoryIndex].setMaxWidth(Double.MAX_VALUE);
          itemButtons[itemIndex][categoryIndex].setMaxHeight(Double.MAX_VALUE);
          itemButtons[itemIndex][categoryIndex].setStyle(
              "-fx-text-fill: gold; -fx-font-size: 24px; -fx-font-weight: bold; -fx-background-color: #0000FF;");
          gridPane.add(itemButtons[itemIndex][categoryIndex], categoryIndex, itemIndex + 1);
          categories
              .get(categoryIndex)
              .getBoardItem(itemIndex)
              .setViz(itemButtons[itemIndex][categoryIndex]);
        }
      }
    }