13.13 CheckBox

Cliquez içi pour plus de vidéos disponibles sur notre chaine youtube !

Hello, so in this video, we will see the "checkbox". So we use a checkbox when there are only 2 choices or statements, for example sometimes when we buy something online, we are asked if we would also like to subscribe to a newsletter, we can subscribe by ticking a box. If we do not want to subscribe, we leave the box unchecked. So let’s add a checkbox to our gridPane to see this in action.So, we go down to after the radio buttons. And I’ll do Checkbox, the text is equal to "subscribe to our newsletter", GridPane.rowIndex ="0" and a GridPane.columnIndex = ""5 " If we execute it that way. When we click on it, we can check it or uncheck it. Now JavaFX control allows 3 states but you need to enable the third state because it is disabled by default. This third state is known as an undetermined state. When the undetermined state is enabled, the checkbox will initially contain a dash. And once the user has clicked on the checkbox, there is no way to retrieve the "dash" by clicking on the control. So let’s add the status by adding the undetermined property to our checkbox and setting it to True. If we execute it. You can see that we have the little dash now. Basically, once you click on it, it is enabled or disabled. So I can’t really think of a real and practical use for it and that’s really not what users expect from a checkbox. I would normally suggest you leave this option disabled, but I just wanted to show you to let you know that it exists, if, for some reason, you can think of a reason to actually use it. So sometimes we only need one check box, but other times we might want to use check boxes instead of radio buttons. Thus, a group of radio buttons allows a user to select a choice from several options, which we have seen. And now, what happens if we want the user to be able to select more than one choice. There are usually several ways to do this, but a common way is to use check boxes instead of radio buttons. Now, we cannot group the check boxes under a Toggle group because the check box does not go down from the toggle group class. But what we can do is visually group the check boxes as we did with the radio buttons. Let’s put our checkbox in a Vbox box and add 2 more checkboxes.I’ll create a Vbox. Here I will erase this checkbox and inside our Vbox we will put the checkbox, which will be dog, cat and bird. If I restart the program. We have our three checkboxes. It’s a vertical because it’s a VBOX, it goes up and down, and you can obviously select more than one option at a time. So I mentioned that the radio buttons come down from the toggle button class. So a toggle button is a full JavaFX control, and a toggle button looks like a normal button, but when we press it it stays pressed when we press it again, it comes out. So let’s quickly add three to our GridPane to see how it works before we finish the video. I’ll put an Hbox here, it will have one, gridPane rowIndex and GridPane columnIndex and inside 3 three toggle group. If we run the program. We have our 3 buttons When we press it It stays pressed and when we press it again, it comes out. That’s it for this video. I’ll see you next time.