Layout in Paint

2016.12.05

 

I suddenly found that I almost forgot about the part about drawing before, and now I plan to take a good look at it again and try my best to lay a solid foundation.



 Take a look at this diagram to understand the relationship between top-level containers, intermediate containers, and components.

1. Create a top-level container

Corresponding to the initialization window of the program, various components such as other menus, toolbars, text boxes, buttons, etc. are placed in the window.

The top-level container is the basis for the display of other graphical interfaces, and other components are directly or indirectly displayed in the top-level container.

There are three types of top-level containers in java, namely JFrame (frame window), JDialog (dialog box), and JApplet (used to design java applets embedded in web pages). A top-level container must be available for setting up a graphical program.

2. Create intermediate containers and components

Corresponds to controls such as menus, toolbars (intermediate containers), text boxes, buttons, radio buttons, and check boxes that appear in the program.

3. Add components to the container

After creating a component in java, you also need to put the component into the corresponding container to display the component in the top-level container, such as a window.

4. Set the position of the component inside the container

Two, that is, according to the relative distance from the container, the layout manager is used to manage the position of the components in the container.

5. Handle events generated by components.

Common intermediate containers are:

JPanel: The most flexible and commonly used intermediate container

JScrollPane: Similar to Jpanel, but provides scroll bars around large or expandable components.



 

BorderLayout//Border layout

        The layout contains multiple sub-panels and is an application-oriented UI-style layout that divides the entire container into 5 parts: east (east), south (south), west (west), north (north) and center.

FlowLayout//Flow layout features are as follows

Regardless of alignment, components are laid out in a left-to-right fashion, with a full row going to the next row.

Set the FlowLayout layout:

JFrame  fr=new JFrame( );

FlowLayout  flow=new FlowLayout( );

fr.setLayout(flow);

The above statement can be simplified to:
fr.setLayout(new FlowLayout());

Set the frame fr as a FlowLayout layout with components left-aligned

fr.setLayout(newFlowLayout(FlowLayout.LEFT));

Set the frame fr as a FlowLayout layout with components left-aligned, and the components have a horizontal spacing of 20 pixels and a vertical spacing of 40 pixels.

fr.setLayout(new  FlowLayout(FlowLayout.LEFT,20,40));

 


 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326932244&siteId=291194637