
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaFX example to add a tooltip to a radio button
Radio Button
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.
Tooltip
Whenever you hover over the mouse pointer over an element (say, button, label, etc..) in your application, the tooltip displays a hint about it. In JavaFX the tooltip is represented by the javafx.scene.control.Tooltip class, you can create a tooltip by instantiating it.
While instantiating the class you need to pass the text to be prompted as a parameter to its constructor (or set it using the setText() method.)
Example
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.RadioButton; import javafx.scene.control.ToggleGroup; import javafx.scene.control.Tooltip; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.stage.Stage; public class Tooltip_ApplicationData extends Application { public void start(Stage stage) { //Creating a label Label label = new Label("Select Fries for Burger Meal:"); label.setFont(new Font("Britannic Bold", 15)); //Creating the Radio buttons RadioButton rb1 = new RadioButton("Regular Fries"); RadioButton rb2 = new RadioButton("King Fries"); RadioButton rb3 = new RadioButton("Medium Peri Peri Fries"); RadioButton rb4 = new RadioButton("Creamy Italian Fries"); //Adding the buttons to the toggle group ToggleGroup group = new ToggleGroup(); group.getToggles().addAll(rb1, rb2, rb3, rb4); //Creating tool tips Tooltip toolTip1 = new Tooltip("70 ₹"); Tooltip toolTip2 = new Tooltip("90 ₹"); Tooltip toolTip3 = new Tooltip("100 ₹"); Tooltip toolTip4 = new Tooltip("120 ₹"); //Adding tool tips to the radio buttons rb1.setTooltip(toolTip1); rb2.setTooltip(toolTip2); rb3.setTooltip(toolTip3); rb4.setTooltip(toolTip4); //Adding the toggle button to the pane VBox vBox = new VBox(10); vBox.setPadding(new Insets(15, 5, 5, 100)); vBox.getChildren().addAll(label, rb1, rb2, rb3, rb4 ); //Setting the stage Scene scene = new Scene(new Group(vBox), 595, 170, Color.BEIGE); stage.setTitle("Tooltip Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output
- Related Questions & Answers
- How to create a Radio Button using JavaFX?
- JavaFX example to set behavior to a button
- How to add an image to a button (action) in JavaFX?
- How to add radio button list in alert dialog?
- How to add a tooltip to a component in Java?
- How to create a Button in JavaFX?
- How to create a Toggle Button in JavaFX?
- How to select a radio button by default in JavaScript?
- How to set OnclickListener on a radio button in android?
- Using Selenium in Python to click/select a radio button.
- JavaFX example to set action listeners to a CheckBox
- Bootstrap Form Radio Button
- How to use Radio button in Android?
- How to find a radio button element by value using Selenium?
- How to add a separator to a Menu in JavaFX?
Advertisements