Created
February 17, 2017 14:35
-
-
Save bugabinga/4f782780ec7d03f9c6abd29d269c3b9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.slider > .axis { | |
/* Moves the Labels up: */ | |
-fx-translate-y: -25.0; | |
/* Aligns Labels to top in their parent: */ | |
-fx-side: top; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.isp.stackoverflow; | |
import javafx.application.Application; | |
import javafx.geometry.Insets; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Slider; | |
import javafx.scene.layout.StackPane; | |
import javafx.stage.Stage; | |
import javafx.util.StringConverter; | |
/** | |
* Shows a {@link Slider} with tick Labels above the track. | |
* | |
* @author okr | |
* @date 17.02.2017 | |
* | |
*/ | |
public class SliderTicksAbove extends Application { | |
@Override | |
public void start(final Stage primaryStage) { | |
final StackPane root = new StackPane(); | |
root.setPadding( new Insets( 16 ) ); | |
final Slider slider = new Slider(); | |
slider.setShowTickLabels( true ); | |
final double sliderMax = slider.getMax(); | |
slider.setLabelFormatter( new StringConverter<Double>() | |
{ | |
@Override | |
public String toString( final Double d ) | |
{ | |
return String.valueOf( (int) (sliderMax - d) ); | |
} | |
@Override | |
public Double fromString( final String str ) | |
{ | |
return sliderMax - Double.parseDouble( str ); | |
} | |
} ); | |
root.getChildren().add( slider ); | |
final Scene scene = new Scene( root ); | |
scene.getStylesheets().add( getClass().getResource( "slider.css" ).toExternalForm() ); | |
primaryStage.setWidth( 400 ); | |
primaryStage.setHeight( 200 ); | |
primaryStage.setScene( scene ); | |
primaryStage.show(); | |
} | |
/** | |
* @param args ignored. | |
*/ | |
public static void main(final String[] args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment