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

Updating custom slider tick label formatter does not redraw tick labels

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • jfx11, 8, jfx17, jfx18, jfx19
    • javafx
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The first call to Slider#setLabelFormatter with a custom formatter updates the labels immediately. However, later changing from one custom formatter to another does not have any immediate effect. Later resizing the window or otherwise forcing a relayout updates the tick labels successfully.

      Calling setLabelFormatter first with null argument, then with the desired value, works fine as a workaround.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Calling Slider#setLabelFormatter with a custom formatter, then again with another formatter.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Tick labels are reformatted/redrawn immediately.
      ACTUAL -
      Tick labels are not redrawn until forced by other event (such as window resize).

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Slider;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.StringConverter;

      /**
       * Test program to demonstrate a bug. The first time the button is pressed the slider ticks are
       * updated. Clicking the button again does nothing. After that the window can be resized to make the
       * changes take effect.
       */
      public class MyTester extends Application {

          private static int formatterCounter = 0;

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

          @Override
          public void start(final Stage aStage) {
              final Slider slider = new Slider(0, 10, 5);
              slider.setShowTickLabels(true);
              slider.setMajorTickUnit(2);

              final Button button = new Button("Update");
              button.setOnAction(aEvent -> {
                  formatterCounter++;
                  System.out.println("Button pushed! (formatterCounter=" + formatterCounter + ")");
                  // slider.setLabelFormatter(null); // Uncomment to make it work.
                  slider.setLabelFormatter(new StringConverter<Double>() {
                      @Override
                      public String toString(final Double aValue) {
                          return "[" + formatterCounter + "] " + aValue;
                      }

                      @Override
                      public Double fromString(final String aString) {
                          return null;
                      }
                  });
              });

              aStage.setScene(new Scene(new VBox(button, slider)));
              aStage.show();
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Calling setLabelFormatter first with null argument, then with the desired value.

      FREQUENCY : always


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

              Created:
              Updated: