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

ValueAxis: incorrect value/coordinate transformation after resize

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u60
    • javafx

      To reproduce, run the example below, press F1 to toggle the width of the axis and note the print out of the displayPosition before/after the resize

      expected:
      "after" different from before,
      "after" should be half of the current width of the axis

      actual:
      after same as before

      Looks like the internal fields (specifically offset and scale) are only updated on the _next_ layout pulse. Should be done immediately - the conversion methods must return the correct conversion at _any_ time.

      As long as axis doesn't comply to its contract, other controls (like f.i. Slider which was my driving force to use the axis in a cleaner sliderSkin, see http://stackoverflow.com/q/34139076/203657) can't fully rely on its services, at least not during a layout round. That's why I (try to :-) uppen the priority to p3.

      The code example:

      public class AxisConversionBug extends Application {

          private Parent getContent() {
              NumberAxis axis = new NumberAxis(0, 100, 25);
              Region region = new Region() {
                  {
                      getChildren().add(axis);
                  }
              };
              BorderPane pane = new BorderPane(region);
              axis.setManaged(false);
              double initial = 100;
              axis.resize(initial, axis.getPrefHeight());
              axis.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
                  if (e.getCode() == KeyCode.F1) {
                      
                      double positionBefore = axis.getDisplayPosition(50);
                      double axisWidth = axis.getWidth() < region.getWidth()
                              ? region.getWidth() : initial;
                      axis.resize(axisWidth, axis.getHeight());
                      // following doen't make a difference
                      // axis.requestAxisLayout();
                      region.requestLayout();
                      double positionAfter = axis.getDisplayPosition(50);
                      LOG.info("position before/after resize: " + positionBefore +
                              " / " + positionAfter + " width: " + axis.getWidth()) ;
                  }
              });
              axis.setFocusTraversable(true);
              axis.requestFocus();
              return pane;
          }

          @Override
          public void start(Stage primaryStage) throws Exception {
              primaryStage.setScene(new Scene(getContent(), 500, 200));
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
       
          @SuppressWarnings("unused")
          private static final Logger LOG = Logger.getLogger(AxisInvalidate.class
                  .getName());

      }

            Unassigned Unassigned
            fastegal Jeanette Winzenburg
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: