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

Updating custom slider tick label formatter does not redraw tick labels

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 8, openjfx11, openjfx17, openjfx18, openjfx19
    • Fix Version/s: tbd
    • Component/s: javafx
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      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


        Attachments

          Activity

            People

            Assignee:
            aghaisas Ajit Ghaisas
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: