1 /* 2 * Copyright (c) 2014, 2016, 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.Pane; 43 import javafx.scene.layout.TilePane; 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 * @preview preview.png 53 * @see javafx.scene.control.Spinner 54 * @docUrl http://www.oracle.com/pls/topic/lookup?ctx=javase80&id=JFXUI336 Using JavaFX UI Controls 55 * 56 * @related /Controls/DialogApp 57 */ 58 public class SpinnerApp extends Application { 59 60 /** 61 * Java main for when running without JavaFX launcher 62 * @param args command line arguments 63 */ 64 public static void main(String[] args) { 65 Application.launch(args); 66 } 67 68 @Override 69 public void start(Stage primaryStage) throws Exception { 70 primaryStage.setScene(new Scene(createContent())); 71 primaryStage.show(); 72 } 73 74 public Parent createContent() { 75 76 String[] styles = { 77 "spinner", // defaults to arrows on right stacked vertically 78 Spinner.STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL, 79 Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL, 80 Spinner.STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL, 81 Spinner.STYLE_CLASS_SPLIT_ARROWS_VERTICAL, 82 Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL 83 }; 84 85 TilePane tilePane = new TilePane(); 86 tilePane.setPrefColumns(6); //preferred columns 87 tilePane.setPrefRows(3); //preferred rows 88 tilePane.setHgap(20); 89 tilePane.setVgap(30); 90 91 Pane root = new Pane(); 92 root.setMinSize(Pane.USE_PREF_SIZE, Pane.USE_PREF_SIZE); 93 root.setMaxSize(Pane.USE_PREF_SIZE, Pane.USE_PREF_SIZE); 94 95 for (int i = 0; i < styles.length; i++) { 96 /* Integer spinners */ 97 SpinnerValueFactory svf = 98 new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 99); 99 Spinner sp = new Spinner(); 100 sp.setValueFactory(svf); 101 sp.getStyleClass().add(styles[i]); 102 sp.setPrefWidth(80); 103 tilePane.getChildren().add(sp); 104 } 105 106 for (int i = 0; i < styles.length; i++) { 107 /* Double spinners */ 108 SpinnerValueFactory svf = 109 new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 1.0, 110 0.5, 0.01); 111 Spinner sp = new Spinner(); 112 sp.setValueFactory(svf); 113 sp.getStyleClass().add(styles[i]); 114 sp.setPrefWidth(90); 115 tilePane.getChildren().add(sp); 116 } 117 118 for (int i = 0; i < styles.length; i++) { 119 /* String spinners */ 120 ObservableList<String> items = 121 FXCollections.observableArrayList("Grace", "Matt", "Katie"); 122 SpinnerValueFactory svf = 123 new SpinnerValueFactory.ListSpinnerValueFactory<>(items); 124 Spinner sp = new Spinner(); 125 sp.setValueFactory(svf); 126 sp.setPrefWidth(100); 127 sp.getStyleClass().add(styles[i]); 128 tilePane.getChildren().add(sp); 129 } 130 131 root.getChildren().add(tilePane); 132 return root; 133 } 134 }