GUI Panel container and layout manager, guipanel

Source: Internet
Author: User

GUI Panel container and layout manager, guipanel

1. Panel is another typical container in AWT, which means it cannot exist independently and must be used in other containers.

1. Other components can be loaded as containers to provide space for placement of components.

2. It cannot exist independently and must be placed in other containers.

3. By default, FlowLayout is used as the layout manager.

1 public class PanelTest extends Frame 2 {3 public static void main (String [] args) 4 {5 Frame f = new Frame (); 6 Panel p = new Panel (); 7 p. add (new TextField (20); 8 p. add (new Button ("Baidu"); 9 f. add (p); 10 f. setBounds (50, 50,300,300); 11 f. setVisible (true); 12} 13}

 

Ii. FlowLayout layout manager

In the FlowLayout layout manager, components flow (arranged) in a certain direction like a flow. When an obstacle (Boundary) occurs, the components are folded back and re-arranged.

Three constructors:

FlowLayout: uses the default Alignment Method, the default Vertical spacing, and horizontal spacing to create the FlowLayout layout manager.

FlowLayout (int align): Creates a FlowLayout layout manager using the specified Alignment Method, default Vertical spacing, and horizontal spacing.

FlowLayout (int align, int hgap, int vgap): Creates a FlowLayout layout manager using the specified Alignment Method, specified Vertical spacing, and horizontal spacing.

 1 public class FlowLayoutTest 2 { 3     public static void main(String[] args) 4     { 5         Frame f = new Frame(); 6         f.setLayout(new FlowLayout(FlowLayout.LEFT,20,5)); 7         Button b1 = new Button("a1"); 8         Button b2 = new Button("a2"); 9         Button b3 = new Button("a3");10         f.add(b1);11         f.add(b2);12         f.add(b3);13         f.pack();14         f.setVisible(true);15         16     }17 }

 

3. BorderLayout layout manager

BorderLayout divides containers into five areas: EAST, SOUTH, WEST, NORTH, and CENTER, common components can be placed in any of the five regions.

Constructor:

BorderLayout (): uses the default horizontal and vertical spacing to create the BorderLayout layout manager.

BorderLayout (int hgap, int vgap): uses the specified horizontal and vertical spacing to create the BorderLayout layout manager.

1 public class BorderLayoutTest extends Frame 2 {3 public static void main (String [] args) 4 {5 Frame f = new Frame (); 6 f. setLayout (new BorderLayout (30, 5); 7 f. add (new Button ("South"), BorderLayout. SOUTH); 8 f. add (new Button ("North"), BorderLayout. NORTH); 9 f. add (new Button ("medium"); 10 f. add (new Button ("East"), BorderLayout. EAST); 11 f. add (new Button ("West"), BorderLayout. WEST); 12 13 f. pack (); 14 f. setVisible (true); 15} 16}

Iv. GridLayout layout manager

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.