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

Baseline calculation for labeled nodes does not work when graphics are set

    XMLWordPrintable

Details

    • x86_64
    • windows_7

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When you mix buttons with and without graphics (e.g. icons) in an HBox with the alignment BASELINE_RIGHT the buttons are not all correctly aligned.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the supplied program: The baseline is completely off for buttons with a small graphic and off by one pixel for the large graphic.
      The problem seems to originate in LabeledSkinBase.computeBaselineOffset. There is no check if the graphic has a smaller height than the text. In that case the graphic can possibly be ignored for baseline calculations. For large graphics there might be missing some kind of snap so that the offset is correct.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All text in the buttons are aligned vertically on the same height.
      ACTUAL -
      The vertical alignment of buttons with graphics is either much too low with small graphics and off by one pixel for large graphics.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.MenuButton;
      import javafx.scene.layout.HBox;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.shape.Shape;
      import javafx.scene.text.Font;
      import javafx.stage.Stage;

      public class FXBaselineTest extends Application {

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

        @Override
        public void start(Stage stage) throws Exception {
          HBox hBox = new HBox(2);
          hBox.setAlignment(Pos.BASELINE_RIGHT);

          Shape bigRect = new Rectangle(30, 30);
          Shape smallRect = new Rectangle(6, 6);

          Button button1 = new Button("Test without graphic");
          button1.setPadding(new Insets(4, 8, 4, 8));
          Button button2 = new Button("Test with small graphic", smallRect);
          Button button3 = new Button("Test with big graphic", bigRect);

          MenuButton menuButton1 = new MenuButton("Menu test without graphic");
          menuButton1.setPadding(new Insets(4, 8, 4, 8));
          MenuButton menuButton2 = new MenuButton("Menu test without graphic and large font size");
          menuButton2.setFont(new Font(20));

          hBox.getChildren().add(button1);
          hBox.getChildren().add(menuButton1);
          hBox.getChildren().add(button2);
          hBox.getChildren().add(button3);
          hBox.getChildren().add(menuButton2);

          Scene scene = new Scene(hBox);
          stage.setScene(scene);
          stage.show();
        }
      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              pmangal Priyanka Mangal (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: