JCheckBox & ItemListener

above picture, the text field reports, user placed a check mark on the check box item 2. Now, we will implement this example.
above picture, the text field reports, user placed a check mark on the check box item 2. Now, we will implement this example.
In this example, we have seven JToggleButton components. First 4 is for the Nationality and second three is for the Sex. Here, these toggle buttons act like a radio button. One can also note that there are two groups here. In a group, only one toggle button can stay in Switched ON state. The above picture shows France and Female is in Selected State. Now, we will implement this example.
The example contains three components. One is a JLabel which tells in what mode the example is in. The button labelled OFF is the JToggleButton and it will switch the state between Selected & Unselected. The text box tells what kind of the state change is made by the user while he/she clicked the Two-State button last time.
In the example below, we have three Java Swing JButtons. All these buttons display a normal image when the JFrame displays. Each button will display three image icons based on the mouse action. The images for Normal, button pressed and mouse-enter are shown in the above screen. Let us proceed with the example and start coding.
This example shows two JButtons. Each button displays an ImageIcon in it. In this example, we will learn how to display an Image Icon in the JButton and how to set the alignment relation between the Image Icon and button text.