Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8088307

HBox with BASELINE alignment and CheckBox has alignment issues

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • tbd
    • 8u40
    • javafx
    • Windows 7 64-bit
      OS X 10.10.3
      Java 8u40

    Description

      See the program below.
      Baseline alignment doesn't work properly for an odd combination of CheckBox and HBox.

      Test case:


      package checkboxbaseline;

      import javafx.application.Application;
      import javafx.geometry.Pos;
      import javafx.scene.Node;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.CheckBox;
      import javafx.scene.control.Label;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Priority;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;


      public class CheckBoxBaseline extends Application {

      @Override
      public void start(Stage primaryStage) {
      HBox h1 = createHBox();

      h1.getChildren().addAll(new Label("Label 1:"), new CheckBox("unwrapped Checkbox - Good"), makeFill(), makeButton());
      HBox h2 = createHBox();
      h2.getChildren().addAll(new Label("Label 2:"), createHBox(new CheckBox("Checkbox wrapped BAD"), makeFill(), makeButton()));
      HBox h3 = createHBox();
      h3.getChildren().addAll(new Label("Label 3:"), createHBox(new CheckBox("Checkbox wrapped Good"), makeButton()));
      HBox h4 = createHBox();
      h4.getChildren().addAll(new Label("Label 4:"), createHBox(new TextField("TextField wrapped Good"), makeFill(), makeButton()));

      VBox v = new VBox(4);
      v.setFillWidth(true);
      v.getChildren().addAll(h1,h2,h3,h4, createHBox(new Label("Notice the alignment on line 2.\n"
      +"Line 4 is constructed exactly the same\n"
      +"except with a TextField instead of a\n"
      +"CheckBox. Why does it work?\n"
      +"The HBox filler (red) has something to do with it.\n"
      +"If I use a Label as a filler the problem goes away.\n")));


      Scene scene = new Scene(v, 300, 250);

      primaryStage.setTitle("Bad BASELINE alignment: Line 2");
      primaryStage.setScene(scene);
      primaryStage.show();
      }

      private Node makeFill() {
      HBox h = new HBox();
      //Label h = new Label(); // using a label fixes the alignment
      h.setMinHeight(3);
      h.setMaxHeight(3);
      h.setPrefHeight(3);
      h.setMaxWidth(Double.MAX_VALUE);
      HBox.setHgrow(h, Priority.SOMETIMES);
      h.setStyle("-fx-border-width: 1px; -fx-border-color: red;");
      return h;
      }

      private HBox createHBox(Node... n) {
      HBox h = createHBox();
      h.getChildren().addAll(n);
      return h;
      }

      private HBox createHBox() {
      HBox h = new HBox(2);
      h.setStyle("-fx-border-width: 1px; -fx-border-color: green;");
      h.setMaxWidth(Double.MAX_VALUE);
      h.setAlignment(Pos.BASELINE_LEFT);
      HBox.setHgrow(h, Priority.ALWAYS);
      return h;
      }

      private Node makeButton() {
      Button menuButton = new Button("X"); //new Button("\u25a4");
      HBox.setHgrow(menuButton, Priority.NEVER);
      return menuButton;
      }

      public static void main(String[] args) {
      launch(args);
      }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            swpalmer Scott Palmer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Imported: