As you know, containers (such as JFrame, JPanel, ...) are used to hold controls in them, but they do not have or default to arrange objects that are not what we want. So we need to use layouts to do this. In other words, Layouts allow us to arrange the controls in the containers in a logical and beautiful way.
Java swing BorderLayout allows you to arrange objects in five main areas (NORTH, SOUTH, WEST, EAST and CENTER) as shown below:
In addition, we can substitute by PAGE START, PAGE END, LINE_START, LINE_END, CENTER and the result is also similar.
- BorderLayout (int hgap, int vgap): Initialize BorderLayout with the distance between the specified positions horizontally and vertically.
File name: LoginFrame.java
Continue LoginFrame.java
Continue LoginFrame.java
The annotations in the code explained quite well what we did, just to note that in the PassWord input we use JPasswordField.
Might be you care how to create java swing JPanel with detail examples:
Java swing BorderLayout allows you to arrange objects in five main areas (NORTH, SOUTH, WEST, EAST and CENTER) as shown below:
In addition, we can substitute by PAGE START, PAGE END, LINE_START, LINE_END, CENTER and the result is also similar.
The code creates java swing BorderLayout
We have two methods of initializing java swing Borderlayout:
- BorderLayout (): Initialize BorderLayout with a default spacing of 0.- BorderLayout (int hgap, int vgap): Initialize BorderLayout with the distance between the specified positions horizontally and vertically.
Create a login frame using java swing BorderLayout
The fact that we use java swing BorderLayout is very common to our programs. For example, the following is an example of a login framework that uses BorderLayout.The login framework uses 1 JPanel as the mainPanel is set BorderLayout, which maintains 5 JPanel child (itemPanel) placed in the 5 positions of BorderLayout respectively. With 3 PANELS at WEST, EAST and CENTER there is a GridLayout of 2 lines and 1 column.File name: LoginFrame.java
Continue LoginFrame.java
Continue LoginFrame.java
The annotations in the code explained quite well what we did, just to note that in the PassWord input we use JPasswordField.
Might be you care how to create java swing JPanel with detail examples:
Comments
Post a Comment