< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/RadioMenuItem.java

Print this page




  70     @Override public void handle(ActionEvent e) {
  71         System.out.println("radio toggled");
  72     }
  73 });
  74 radioItem1.setToggleGroup(toggleGroup);
  75 RadioMenuItem radioItem2 = new RadioMenuItem("Option 2");
  76 radioItem.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  77     @Override public void handle(ActionEvent e) {
  78         System.out.println("radio toggled");
  79     }
  80 });
  81 radioItem2.setToggleGroup(toggleGroup);
  82 
  83 </code></pre>
  84  *
  85  * In this example, with both RadioMenuItem's assigned to the same
  86  * {@link javafx.scene.control.ToggleGroup ToggleGroup}, only one item may be
  87  * selected at any one time, and should
  88  * the selection change, the ToggleGroup will take care of deselecting the
  89  * previous item.
  90 </code></pre>
  91  *
  92  * @see MenuItem
  93  * @see Menu
  94  * @since JavaFX 2.0
  95  */
  96 public class RadioMenuItem extends MenuItem implements Toggle {
  97 
  98     /***************************************************************************
  99      *                                                                         *
 100      * Constructors                                                            *
 101      *                                                                         *
 102      **************************************************************************/
 103 
 104     /**
 105      * Constructs a RadioMenuItem with no display text.
 106      */
 107     public RadioMenuItem() {
 108         this(null,null);
 109     }
 110 
 111     /**
 112      * Constructs a RadioMenuItem and sets the display text with the specified text.

 113      */
 114     public RadioMenuItem(String text) {
 115         this(text,null);
 116     }
 117 
 118     /**
 119      * Constructs a RadioMenuItem and sets the display text with the specified text
 120      * and sets the graphic {@link Node} to the given node.


 121      */
 122     public RadioMenuItem(String text, Node graphic) {
 123         super(text,graphic);
 124         getStyleClass().add(DEFAULT_STYLE_CLASS);
 125     }
 126 
 127 
 128 
 129     /***************************************************************************
 130      *                                                                         *
 131      * Properties                                                              *
 132      *                                                                         *
 133      **************************************************************************/
 134 
 135     // --- Toggle Group
 136     /**
 137      * Represents the {@link ToggleGroup} that this RadioMenuItem belongs to.
 138      */
 139     private ObjectProperty<ToggleGroup> toggleGroup;
 140     @Override public final void setToggleGroup(ToggleGroup value) {




  70     @Override public void handle(ActionEvent e) {
  71         System.out.println("radio toggled");
  72     }
  73 });
  74 radioItem1.setToggleGroup(toggleGroup);
  75 RadioMenuItem radioItem2 = new RadioMenuItem("Option 2");
  76 radioItem.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  77     @Override public void handle(ActionEvent e) {
  78         System.out.println("radio toggled");
  79     }
  80 });
  81 radioItem2.setToggleGroup(toggleGroup);
  82 
  83 </code></pre>
  84  *
  85  * In this example, with both RadioMenuItem's assigned to the same
  86  * {@link javafx.scene.control.ToggleGroup ToggleGroup}, only one item may be
  87  * selected at any one time, and should
  88  * the selection change, the ToggleGroup will take care of deselecting the
  89  * previous item.

  90  *
  91  * @see MenuItem
  92  * @see Menu
  93  * @since JavaFX 2.0
  94  */
  95 public class RadioMenuItem extends MenuItem implements Toggle {
  96 
  97     /***************************************************************************
  98      *                                                                         *
  99      * Constructors                                                            *
 100      *                                                                         *
 101      **************************************************************************/
 102 
 103     /**
 104      * Constructs a RadioMenuItem with no display text.
 105      */
 106     public RadioMenuItem() {
 107         this(null,null);
 108     }
 109 
 110     /**
 111      * Constructs a RadioMenuItem and sets the display text with the specified text.
 112      * @param text the display text
 113      */
 114     public RadioMenuItem(String text) {
 115         this(text,null);
 116     }
 117 
 118     /**
 119      * Constructs a RadioMenuItem and sets the display text with the specified text
 120      * and sets the graphic {@link Node} to the given node.
 121      * @param text the display text
 122      * @param graphic the graphic node
 123      */
 124     public RadioMenuItem(String text, Node graphic) {
 125         super(text,graphic);
 126         getStyleClass().add(DEFAULT_STYLE_CLASS);
 127     }
 128 
 129 
 130 
 131     /***************************************************************************
 132      *                                                                         *
 133      * Properties                                                              *
 134      *                                                                         *
 135      **************************************************************************/
 136 
 137     // --- Toggle Group
 138     /**
 139      * Represents the {@link ToggleGroup} that this RadioMenuItem belongs to.
 140      */
 141     private ObjectProperty<ToggleGroup> toggleGroup;
 142     @Override public final void setToggleGroup(ToggleGroup value) {


< prev index next >