JavaFX Toggle Button

0

JavaFX Toggle Button tutorial:

  • JavaFx Toggle Button has two conditions as selected or not selected.
  • So toggle button also used in group to select one or none.

Constructors of togglebutton:

  • ToggleButton()Creates a toggle button with an empty string for its label.
  • ToggleButton(String text)Creates a toggle button with the specified text as its label.
  • ToggleButton(String text, Node graphic)Creates a toggle button with the specified text and icon for its label.

Example using toggle group:

 

Output :

Explanation of toggle group example :

    • We create new toggle button AS

ToggleButton tb1 = new ToggleButton(" Yes ");

    • To Set toggle group to toggle button

tb1.setToggleGroup(group);

    • To set a value to toggle button we use setUserData() method AS

tb1.setUserData("I Don't Like it");

    • To print the value of tb1 on console screen using

getUserData() which return the Value of toggle button

Share.

Leave A Reply