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

Non-intuitive baseline alignment for labeled controls with graphics

    XMLWordPrintable

Details

    • b10
    • x86
    • other

    Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.14393]

      A DESCRIPTION OF THE PROBLEM :
      When a Labeled control containing graphics is put into an HBox with alignment = Pos.BASELINE_LEFT, baseline of the control's text does not match that of the other labels in the HBox.

      The reason is that the baseline for a Labeled control is taken to be an average of text's baseline and the graphic's bottom edge, see `LabeledSkinBase#computeBaselineOffset()`.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a view equivalent to the following FXML:

      <HBox alignment="BASELINE_LEFT" fillHeight="false">
        <children>
          <Button text="Button 1" />
          <Label text="Label 1" />
          <Button text="Button 2">
            <font><Font size="12.0" /></font>
            <graphic>
              <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="15.0" stroke="BLACK" strokeType="INSIDE" width="15.0" />
            </graphic>
          </Button>
        </children>
      </HBox>


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Texts "Button 1", "Label 1" and "Button 2" should have the same vertical align.
      ACTUAL -
      "Button 1" and "Label 1" have the same vertical align, "Button 2" is offset vertically.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      One can override the control's skin to ignore the graphic height when calculating the baseline. This solution is rather nasty as you'd have to do an identical override for each LabeledSkin subclass.

      Attachments

        Issue Links

          Activity

            People

              kpk Karthik P K
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: