1 /* 2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package hello; 27 28 import static javafx.scene.paint.Color.GHOSTWHITE; 29 import javafx.application.Application; 30 import javafx.collections.ObservableList; 31 import javafx.scene.Group; 32 import javafx.scene.Node; 33 import javafx.scene.Scene; 34 import javafx.scene.control.ToggleButton; 35 import javafx.scene.control.ToggleGroup; 36 import javafx.scene.layout.VBox; 37 import javafx.stage.Stage; 38 39 /** 40 * Demo for {@code ToggleButton}. 41 */ 42 public class HelloToggleButton extends Application { 43 44 public static void main(String[] args) { 45 Application.launch(args); 46 } 47 48 @Override public void start(Stage stage) { 49 // Scene scene = newScene(); 50 51 final ToggleGroup group = new ToggleGroup(); 52 group.selectedToggleProperty().addListener(ov -> System.out.println("UserData for selected Toggle: " + 53 (group.getSelectedToggle() == null ? "****** no selected toggle******" : 54 group.getSelectedToggle().getUserData()))); 55 56 ToggleButton button1 = new ToggleButton("No, *I* am your father"); 57 button1.setUserData("Button 1"); 58 button1.setToggleGroup(group); 59 button1.setSelected(true); 60 61 ToggleButton button2 = new ToggleButton("Nooooooooo!"); 62 button2.setUserData("Button 2"); 63 button2.setLayoutY(40); 64 button2.setToggleGroup(group); 65 66 ToggleButton button3 = new ToggleButton("No, *I* am your father"); 67 // button1.setUserData("Button 1"); 68 button3.setToggleGroup(group); 69 // button1.setSelected(true); 70 71 ToggleButton button4 = new ToggleButton("Nooooooooo!"); 72 // button2.setUserData("Button 2"); 73 // button2.setLayoutY(40); 74 button4.setToggleGroup(group); 75 76 VBox vbox = new VBox(10, button1, button2, button3, button4); 77 78 Scene scene = new Scene(vbox); 79 // ObservableList<Node> content = ((Group)scene.getRoot()).getChildren(); 80 // content.add(button1); 81 // content.add(button2); 82 // content.add(button3); 83 // content.add(button4); 84 85 stage.setScene(scene); 86 stage.show(); 87 } 88 89 // private static Stage newStage() { 90 // Stage stage = new Stage(); 91 // stage.setTitle("Hello ToggleButton"); 92 // stage.setWidth(600); 93 // stage.setHeight(450); 94 // return stage; 95 // } 96 97 // private static Scene newScene() { 98 // Scene scene = new Scene(new Group()); 99 // scene.setFill(GHOSTWHITE); 100 // return scene; 101 // } 102 }