Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8126929

ToggleGroup.getToggles().setAll() throws IllegalArgumentException: Duplicate toggles are not allow in a ToggleGroup.

XMLWordPrintable

      The following code

              RadioMenuItem option1 = new RadioMenuItem("Option 1");
              RadioMenuItem option2 = new RadioMenuItem("Option 2");
              RadioMenuItem option3 = new RadioMenuItem("Option 3");
              
              ToggleGroup options = new ToggleGroup();
              options.getToggles().setAll(option1, option2, option3);

      results in

      Exception in Application start method
      Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
      at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
      at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
      at java.lang.Thread.run(Thread.java:662)
      Caused by: java.lang.IllegalArgumentException: Duplicate toggles are not allow in a ToggleGroup.
      at javafx.scene.control.ToggleGroup$1.onProposedChange(ToggleGroup.java:63)
      at com.sun.javafx.collections.VetoableObservableList.add(VetoableObservableList.java:165)
      at com.sun.javafx.collections.ObservableListWrapper.add(ObservableListWrapper.java:144)
      at javafx.scene.control.RadioMenuItem$1.invalidated(RadioMenuItem.java:151)
      at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:129)
      at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
      at javafx.scene.control.RadioMenuItem.setToggleGroup(RadioMenuItem.java:134)
      at javafx.scene.control.ToggleGroup$1.onChanged(ToggleGroup.java:87)
      at com.sun.javafx.collections.VetoableObservableList.callObservers(VetoableObservableList.java:83)
      at com.sun.javafx.collections.ObservableListWrapper.setAll(ObservableListWrapper.java:303)
      at com.sun.javafx.collections.VetoableObservableList.setAll(VetoableObservableList.java:92)
      at com.sun.javafx.collections.ObservableListWrapper.setAll(ObservableListWrapper.java:314)
      at Bug.start(Bug.java:20)
      at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
      at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
      at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
      ... 1 more

            Unassigned Unassigned
            mrkam Alexander Kuznetcov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: