- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a Radio Button using JavaFX?
A button is a component, which performs an action (like submit, login, etc..) when pressed. It is usually labeled with a text or an image specifying the respective action.
A radio button is a type of button, which is circular in shape. It has two states, selected and deselected. Generally, radio buttons are grouped using toggle groups, where you can only select one of them.
You can create a radio button in JavaFX by instantiating the javafx.scene.control.RadioButton class, which is the subclass of the ToggleButton class. Action is generated whenever a radio button is pressed or released. You can set a radio button to a group using the setToggleGroup() method.
Example
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.RadioButton; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.stage.Stage; public class RadioButtonExample extends Application { @Override public void start(Stage stage) { //Creating toggle buttons RadioButton button1 = new RadioButton("Java"); RadioButton button2 = new RadioButton("Python"); RadioButton button3 = new RadioButton("C++"); //Toggle button group ToggleGroup group = new ToggleGroup(); button1.setToggleGroup(group); button2.setToggleGroup(group); button3.setToggleGroup(group); //Adding the toggle button to the pane VBox box = new VBox(5); box.setFillWidth(false); box.setPadding(new Insets(5, 5, 5, 50)); box.getChildren().addAll(button1, button2, button3); //Setting the stage Scene scene = new Scene(box, 595, 150, Color.BEIGE); stage.setTitle("Toggled Button Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output
- Related Articles
- How to create radio button similar to the toggle button using Bootstrap
- JavaFX example to add a tooltip to a radio button
- How to create a Button in JavaFX?
- How to create Mini Horizontal Radio button controlgroups using jQuery Mobile?
- How to create a Toggle Button in JavaFX?
- How to uncheck a radio button using JavaScript/jQuery?
- How to find a radio button element by value using Selenium?
- How to create a circle using JavaFX?
- How to create a Rectangle using JavaFX?
- How to create a Line using JavaFX?
- How to create a Polygon using JavaFX?
- How to create a Polyline using JavaFX?
- How to create a CubicCurve using JavaFX?
- How to create a QuadCurve using JavaFX?
- How to create a label using JavaFX?

Advertisements