/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. */ package helloworld; import com.sun.javafx.css.StyleableProperty; import com.sun.javafx.css.Stylesheet; import javafx.application.Application; import javafx.application.Platform; import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.chart.NumberAxis; import javafx.scene.control.Button; import javafx.scene.control.Slider; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.stage.Stage; /** * * @author jcambon */ public class TestSliderCss extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) { stage.setTitle("Slider CSS"); final AnchorPane root = new AnchorPane(); Scene scene = new Scene(root, 200, 200); scene.setFill(Color.GHOSTWHITE); final Slider slider = new Slider(); slider.setShowTickLabels(true); slider.setShowTickMarks(true); Button button = new Button("Reset props"); button.setOnAction(new EventHandler() { public void handle(ActionEvent t) { Parent parentSkin = (Parent) slider.getSkin(); for (Node child : parentSkin.getChildrenUnmodifiable()) { if (child instanceof NumberAxis) { // Reset to initial value for (StyleableProperty p : StyleableProperty.getStyleables(child)) { @SuppressWarnings("unchecked") final StyleableProperty sp = (StyleableProperty) p; Object initialValue = sp.getInitialValue(child); sp.set(child, initialValue, Stylesheet.Origin.USER_AGENT); System.out.println("Reset " + sp.getProperty() + " to " + initialValue); } } } } }); VBox vbox = new VBox(30); AnchorPane.setLeftAnchor(vbox, 20.0); AnchorPane.setRightAnchor(vbox, 20.0); vbox.setPadding(new Insets(20, 0, 0, 20)); vbox.getChildren().setAll(slider, button); root.getChildren().add(vbox); stage.setScene(scene); stage.show(); } }