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

ToolBar shows overflow menu with fractional scale

XMLWordPrintable

    • Fix Understood
    • x86_64
    • windows

      ADDITIONAL SYSTEM INFORMATION :
      x86 / Windows 11 / Java 23.0.1

      A DESCRIPTION OF THE PROBLEM :
      There's a bug whenever using a ToolBar on Windows if you set the resolution scale > 100%. E.g., 125%, where the ToolBar might create the overflow menu despite there being plenty of available space. This is down to a rounding error where two numbers should be regarded as equal but are not.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      Very easy to reproduce the above, set your scale to 125% and run this:

      public class ToolbarBugApp extends Application {

          @Override
          public void start(Stage primaryStage) {
              BorderPane bp = new BorderPane();
              // Wrapping in HBox and using button with 13+ chars causes bug
              bp.setTop(new HBox(new ToolBar(new Button("Create Schema")))); // BUG
              // bp.setTop(new ToolBar(new Button("Create Schema"))); // NO BUG (no HBox)
              // bp.setTop(new HBox(new ToolBar(new Button("Create Schem")))); // NO BUG (12 chars)
              primaryStage.setScene(new Scene(bp, 600, 400));
              primaryStage.show();
          }

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

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      That the ToolBar does not render the overflow menu.
      ACTUAL -
      The ToolBar does renders the overflow menu.

      ---------- BEGIN SOURCE ----------
      As above. If it doesn't work for you, try different string lengths.

      The bug can be found in ToolBarSkin's getOverflowNodeIndex(double length), where "x" and "length" are not equal when they should be (due to a very tiny rounding error). When x > length, it incorrectly assumes that overflow is required.
      ---------- END SOURCE ----------

        1. in-toolbarskin.png
          in-toolbarskin.png
          177 kB
        2. ToolBar-100.png
          ToolBar-100.png
          6 kB
        3. ToolBar-125.png
          ToolBar-125.png
          7 kB

            angorya Andy Goryachev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: