1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. 3 * All rights reserved. Use is subject to license terms. 4 * 5 * This file is available and licensed under the following license: 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * - Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the distribution. 16 * - Neither the name of Oracle Corporation nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package ensemble.samples.controls.spinner; 33 34 import javafx.application.Application; 35 import javafx.collections.FXCollections; 36 import javafx.collections.ObservableList; 37 import javafx.scene.Group; 38 import javafx.scene.Parent; 39 import javafx.scene.Scene; 40 import javafx.scene.control.Spinner; 41 import javafx.scene.control.SpinnerValueFactory; 42 import javafx.scene.layout.HBox; 43 import javafx.scene.layout.VBox; 44 import javafx.stage.Stage; 45 46 import java.util.Arrays; 47 48 /** 49 * A sample that demonstrates the Spinner control. 50 * 51 * @sampleName SpinnerApp 52 * @see javafx.scene.control.Spinner 53 * @related /Controls/Spinner 54 */ 55 public class SpinnerApp extends Application { 56 57 /** 58 * Java main for when running without JavaFX launcher 59 * @param args command line arguments 60 */ 61 public static void main(String[] args) { 62 Application.launch(args); 63 } 64 65 @Override 66 public void start(Stage primaryStage) throws Exception { 67 primaryStage.setScene(new Scene(createContent())); 68 primaryStage.show(); 69 } 70 71 public Parent createContent() { 72 73 HBox intBlock = new HBox(30); 74 HBox stringBlock = new HBox(30); 75 HBox doubleBlock = new HBox(30); 76 77 String[] styles = { 78 "spinner", // defaults to arrows on right stacked vertically 79 Spinner.STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL, 80 Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL, 81 Spinner.STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL, 82 Spinner.STYLE_CLASS_SPLIT_ARROWS_VERTICAL, 83 Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL 84 }; 85 86 Spinner[] intSpinners = new Spinner[styles.length]; 87 Spinner[] stringSpinners = new Spinner[styles.length]; 88 Spinner[] doubleSpinners = new Spinner[styles.length]; 89 90 for (int i = 0; i < styles.length; i++) { 91 /* Integer spinners */ 92 SpinnerValueFactory svf = 93 new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 99); 94 Spinner sp = new Spinner(); 95 sp.setValueFactory(svf); 96 sp.getStyleClass().add(styles[i]); 97 sp.setPrefWidth(80); 98 intSpinners[i] = sp; 99 100 /* Double spinners */ 101 svf = new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 1.0, 102 0.5, 0.01); 103 sp = new Spinner(); 104 sp.setValueFactory(svf); 105 sp.getStyleClass().add(styles[i]); 106 sp.setPrefWidth(90); 107 doubleSpinners[i] = sp; 108 109 /* String spinners */ 110 ObservableList<String> items = 111 FXCollections.observableArrayList("Grace", "Matt", "Katie"); 112 svf = new SpinnerValueFactory.ListSpinnerValueFactory<>(items); 113 sp = new Spinner(); 114 sp.setValueFactory(svf); 115 sp.setPrefWidth(100); 116 sp.getStyleClass().add(styles[i]); 117 stringSpinners[i] = sp; 118 } 119 120 intBlock.getChildren().addAll(Arrays.asList(intSpinners)); 121 doubleBlock.getChildren().addAll(Arrays.asList(doubleSpinners)); 122 stringBlock.getChildren().addAll(Arrays.asList(stringSpinners)); 123 124 doubleBlock.setLayoutY(100); 125 stringBlock.setLayoutY(200); 126 127 return new VBox(25, intBlock, doubleBlock, stringBlock); 128 } 129 }