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

setBorder doesn't update the Insets

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u20
    • 8
    • javafx
    • RHELS 6.4 x86_64
      JavaFX 1.8 EA b108
      IntelliJ IDEA Community Edition 13.0.1

      Second (and subsequent) calls to setBorder on a subclass of Region does not fully update the Border property. My test is using a single BorderStroke. It seems that the Paint, Widths, Radii, etc get updated but not the Insets.

      This program demonstrates the issue:

      package sample;

      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.layout.*;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;

      public class Main extends Application
      {
          class SubRegion extends Region
          {
              private final Rectangle rect = new Rectangle(10,10, Color.BLACK);

              SubRegion() {
                  getChildren().add(rect);
              }

              @Override
              protected void layoutChildren() {
                  Insets in = getInsets();

                  System.out.println(in);

                  rect.setX(in.getLeft());
                  rect.setY(in.getTop());
                  rect.setWidth(getWidth() - in.getLeft() - in.getRight());
                  rect.setHeight(getHeight() - in.getTop() - in.getBottom());
              }
          }


          @Override
          public void start(Stage stage) throws Exception
          {
              final BorderWidths borderWidth2 = new BorderWidths(2);

              final Insets firstInsets = new Insets(5, 5, 100, 100); // TRBL
              final Insets secondInsets = new Insets(120, 120, 3, 3); // TRBL

              final Border orange_border = new Border(new BorderStroke(Color.ORANGE, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, borderWidth2, firstInsets));
              final Border green_border = new Border(new BorderStroke(Color.GREEN, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, borderWidth2, secondInsets));

              SubRegion sr = new SubRegion();

              //
              // Uncomment lines for these tests:
              //
              // Test Name | Lines UNcommented | Result
              // -----------------|-------------------|-----------------------------------------------
              // orange only | 1 | orange border around black box in upper right
              // green only | 3 | green border around black box in lower left
              // demonstrate bug | 1 and 3 | green border in lower left, black box in the upper right (at the former Insets)
              // workaround | 1, 2 and 3 | same as "green only" ie. correct
              //
              sr.setBorder(orange_border); // line "1"
              //sr.setBorder(null); // line "2"
              sr.setBorder(green_border); // line "3"

              stage.setTitle("Hello World");
              stage.setScene(new Scene(sr, 300, 275));
              stage.show();
          }

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

            msladecek Martin Sládeček
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: