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();
    }
}
