Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.geometry.Insets;
  3. import javafx.scene.Scene;
  4. import javafx.scene.control.Label;
  5. import javafx.scene.control.Slider;
  6. import javafx.scene.layout.Pane;
  7. import javafx.scene.layout.StackPane;
  8. import javafx.stage.Stage;
  9.  
  10. public class SliderWithLabeledThumb extends Application {
  11.  
  12. @Override
  13. public void start(Stage primaryStage) {
  14. Slider slider = new Slider();
  15. StackPane root = new StackPane(slider);
  16. root.setPadding(new Insets(20));
  17.  
  18. Scene scene = new Scene(root);
  19.  
  20. slider.applyCss();
  21. slider.layout();
  22. Pane thumb = (Pane) slider.lookup(".thumb");
  23. Label label = new Label();
  24. label.textProperty().bind(slider.valueProperty().asString("%.1f"));
  25. thumb.getChildren().add(label);
  26.  
  27.  
  28. primaryStage.setScene(scene);
  29. primaryStage.show();
  30.  
  31. }
  32.  
  33. public static void main(String[] args) {
  34. launch(args);
  35. }
  36. }
  37.  
  38. public class MainViewController implements Initializable {
  39.  
  40. @FXML private VBox root;
  41. private Slider timeSlider;
  42.  
  43. @Override
  44. public void initialize(URL location, ResourceBundle resources) {
  45. timeSlider = new Slider();
  46. root.getChildren.add(timeSlider);
  47. timeSlider.setMax(360);
  48. timeSlider.setMin(0);
  49. timeSlider.setCursor(Cursor.OPEN_HAND);
  50. timeSlider.applyCss();
  51. timeSlider.layout();
  52.  
  53. Pane thumb = (Pane) timeSlider.lookup(".thumb");
  54. Label label = new Label();
  55. label.textProperty().bind(timeSlider.valueProperty().asString("%.1f"));
  56. // the following line points to thumb, which is null then… (debugger proof)
  57. thumb.getChildren().add(label);
  58. }
  59. }
  60.  
  61. public class Main extends Application {
  62. @Override
  63. public void start(Stage primaryStage) {
  64. try {
  65. FXMLLoader loader = new FXMLLoader();
  66. loader.setLocation(getClass().getResource("MainView.fxml"));
  67. Parent root = loader.load();
  68. Scene scene = new Scene(root,800,600);
  69. scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
  70. primaryStage.setScene(scene);
  71. primaryStage.show();
  72. } catch(Exception e) {
  73. e.printStackTrace();
  74. }
  75. }
  76.  
  77. public static void main(String[] args) {
  78. launch(args);
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement