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.
It is a simple example which has only two components in it. One is JButton and the other one JLabel. When user clicks the Flip Mode button, the Label changes its caption from Read Mode to Write Mode. Upon clicking the button again, the label restores its original caption Read Mode. So during each click, the Label will alternate between the text Read Mode & Write Mode. Let us proceed with the coding:
The finished example is showing a JTextArea component. You can also see how it is showing the multi-line text in it. Here in the above picture, complete text content is not visible in the component. But, the component has a scroll bar which we can scroll to view the remaining content. Our finished example display only the vertical scroll bar and when we progress through the example, we will see how to provide the horizontal scroll bar as well