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

javafx.scene.shape.Polygon layout bounds is too large if stroke is not null

    XMLWordPrintable

Details

    • Bug
    • Status: Open
    • P4
    • Resolution: Unresolved
    • 8u66
    • tbd
    • javafx
    • x86
    • other

    Description

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

      ADDITIONAL OS VERSION INFORMATION :
      OS X Yosemite (10.10.5)

      A DESCRIPTION OF THE PROBLEM :
      For a javafx.scene.shape.Polygon the layout bounds seem to be 0.5 pixels wider (in each direction) than the actually painted polygon area when a stroke is set and the stroke type is either CENTERED or OUTSIDE.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The layout bounds should fit the polygon (including its stroke) exactly.
      ACTUAL -
      There is a 0.5 pixel gap in each direction in case a stroke is set and stroke type is either CENTERED or OUTSIDE.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package org.eclipse.gef4.fx.examples.snippets;

      import javafx.application.Application;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Polygon;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.transform.Scale;
      import javafx.stage.Stage;

      /**
       * @author Alexander Nyßen (alexander.nyssen@itemis.de)
       */
      public class PolygonLayoutBoundsBug extends Application {

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

      @Override
      public void start(Stage primaryStage) throws Exception {
      final Polygon p = new Polygon(10, 30, 20, 20, 20, 40);
      p.setFill(Color.RED);
      p.setStroke(Color.BLACK);

      final Rectangle r = new Rectangle();
      r.setFill(new Color(0, 0, 1, 0.5));
      r.setX(p.getLayoutBounds().getMinX());
      r.setY(p.getLayoutBounds().getMinY());
      r.setWidth(p.getLayoutBounds().getWidth());
      r.setHeight(p.getLayoutBounds().getHeight());

      Group g = new Group(r, p);
      g.getTransforms().add(new Scale(10, 10));
      Scene scene = new Scene(g, 500, 500);
      primaryStage.setScene(scene);
      primaryStage.sizeToScene();
      primaryStage.show();
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      We have to compensate the layout bounds in all places where we want "tight" bounds.

      Attachments

        Activity

          People

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: