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
The example shows three JTextFields. Each text fields contains the text in different text colour. Also, we may notice that the texts alignments are different. First JTextField shows the text left aligned. The second control shows the text aligned towards the middle of the text field. Final text field shows the text right aligned. You may also notice we display all texts in a bigger size than the default.
This example has four JLabels in it and a FlowLayout Manager is taking care of laying out these labels. Each label uses a unique border to draw around it. Since JLabel is a component, one can apply the same technique for other components as well. For example, a JTextField can use same technique to draw the border. Now, we can have a look at the Bevel Raised border in the picture above and the JLabel looks like a button, right? But it is not. We also set a Font for all the JLabels in this example.
In the this example, we can see how a JFrame Window looks. The three buttons in the top right clearly show how it was drawn using line and rectangles using in-built graphics API. The window displays the title in the frame. And in the Gray area, three JLabels are sitting. That is all and nothing special here.