- 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
What is tri state checkBox, How to create a tri state checkBox in JavaFX?
A checkbox is a type of selection control, which is square in shape with a tick mark int it. Generally, a checkbox has two states checked and unchecked.
Depending on the GUI (technology) we can also have a third state named undefined/undetermined, which indicates the state of the current checkbox is neither checked nor unchecked.
JavaFX supports tristate checkboxes, the javafx.scene.control.CheckBox class represents a checkbox and it contains three boolean properties −
allowIndeterminate − This property specifies whether a checkbox should have all the three states. You can set the value to this property using the setAllowIndeterminate() method.
indeterminate − This property specifies whether a checkbox is in undefined states. You can set the value to this property using the setIndeterminate() method.
selected − This property specifies whether the current checkbox is selected. You can set the value to this property using the setSelected() method.
To toggle through all the three states −
Instantiate the CheckBox class.
Invoke the setAllowIndeterminate() method by passing the boolean value true as an argument.
Invoke the setIndeterminate() method by passing the boolean value true as an argument.
Add the created checkbox to the parent node.
Example
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.stage.Stage; public class CheckBox_Undefined_State extends Application { public void start(Stage stage) { //Creating the check boxes CheckBox checkBox1 = new CheckBox("Salary"); CheckBox checkBox2 = new CheckBox("Over Time Allowence"); CheckBox checkBox3 = new CheckBox("Bonus"); CheckBox checkBox4 = new CheckBox("Night Shift Allowence"); Label label = new Label("Select Recieved Allowences:"); Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12); label.setFont(font); //Setting the indeterminate state true checkBox2.setAllowIndeterminate(true); checkBox2.setIndeterminate(true); checkBox4.setAllowIndeterminate(true); checkBox4.setIndeterminate(true); //Adding the toggle button to the pane VBox vBox = new VBox(5); vBox.setPadding(new Insets(5, 5, 5, 50)); vBox.getChildren().addAll(label, checkBox1, checkBox2, checkBox3, checkBox4); //Setting the stage Scene scene = new Scene(vBox, 595, 150, Color.BEIGE); stage.setTitle("Check Box Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output
- Related Articles
- How to handle when checkbox 'checked state' changed event in jQuery?
- JavaFX example to set action listeners to a CheckBox
- How to create a listView with a checkBox in Kotlin?
- How to show a checkbox in reactnative?
- How to use checkbox in Android?
- How to check whether a checkbox is checked in JavaScript?
- How to use CheckBox in Android Kotlin?
- How to check whether a checkbox is checked with JavaScript?
- How to bold text in checkbox in Excel?
- How to set checkbox size in HTML/CSS?
- Bootstrap Form CheckBox
- Bootstrap checkbox class
- jQuery :checkbox Selector
- How to disable/ enable checkbox with jQuery?
- How to Auto-Centre a Checkbox in a Cell in Excel?
