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

[Slider] Slider minHeight does not take tick marks into account

    XMLWordPrintable

Details

    Description

      minHeight() of a slider does not include the height of tick marks or tick labels. This breaks compact layouts since the slider will be rendered partially outside its bounds.

      The solution would be to take the tick marks and labels height into account when calculating minHeight()

      The same issue applies for vertical sliders.

      Is there any reason minHeight should differ from prefHeight()?

      Workaround: slider.setMinHeight(USE_PREF_SIZE);

      The following example shows four sliders in a gridpane. When making the window smaller vertically, some sliders start to render outside their grid cells.

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Slider;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.RowConstraints;
      import javafx.stage.Stage;

      public class SliderHeightSample extends Application
      {
          public static void main(final String[] args)
          {
              launch(args);
          }

          @Override
          public void start(final Stage stage) throws Exception
          {
              final GridPane gridPane = new GridPane();
              gridPane.setGridLinesVisible(true);
              gridPane.getRowConstraints().setAll(
                  new RowConstraints(50),
                  new RowConstraints(),
                  new RowConstraints(50)
                  );

              final Slider slider1 = new Slider(0, 10, 0);
              final Slider slider2 = new Slider(0, 10, 3);
              final Slider slider3 = new Slider(0, 10, 6);
              final Slider slider4 = new Slider(0, 10, 9);

              // Uncomment for expected behavior
              // slider4.setMinHeight(Control.USE_PREF_SIZE);

              slider2.setShowTickMarks(true);
              slider2.setShowTickLabels(false);

              slider3.setShowTickMarks(false);
              slider3.setShowTickLabels(true);

              slider4.setShowTickMarks(true);
              slider4.setShowTickLabels(true);

              gridPane.add(slider1, 0, 1);
              gridPane.add(slider2, 1, 1);
              gridPane.add(slider3, 2, 1);
              gridPane.add(slider4, 3, 1);

              stage.setScene(new Scene(gridPane));
              stage.show();
          }

      }

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: