Java Learning Notes (45)-Layout manager

Source: Internet
Author: User

FlowLayout Streaming layout Manager
/ * * FlowLayout streaming layout manager */ Public classTest03 { Public Static void Main(string[] args) {Frame frame=NewFrame ("My Frame"); Button btn1=NewButton ("Button 1"); Button btn2=NewButton ("Button 2"); Button btn3=NewButton ("Button 3"); Button btn4=NewButton ("button 4");        Frame.add (BTN1);        Frame.add (BTN2);        Frame.add (BTN3);        Frame.add (BTN4); Frame.setsize ( $, $); Frame.setlocationrelativeto (NULL);//frame.setlayout (New FlowLayout ());//Set the form layout to flow layout, default to Border layoutFrame.setlayout (NewFlowLayout (Flowlayout.left,Ten,Ten));//Set the form layout to flow layout, default to Border layoutFrame.setvisible (true); }}
BorderLayout Border layout Manager
 import java.awt.BorderLayout; import Java.awt.Button; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Frame;/ * *borderlayout Border layout manager * / Public  class Test04 {     Public Static voidMain (string[] args) {Frame frame=NewFrame ("My Frame"); Button btn1=NewButton ("Button 1"); Button btn2=NewButton ("Button 2"); Button btn3=NewButton ("Button 3"); Button btn4=NewButton ("button 4"); Button btn5=NewButton ("button 5"); Frame.setlayout (NewBorderLayout (Ten,5)); Frame.add ("North", BTN1); Frame.add ("South", BTN2); Frame.add ("West", BTN3); Frame.add ("East", BTN4); Frame.add ("Center", BTN5);//Add components to center middle area by defaultFrame.add ("North",NewButton ("button 6")); Frame.setsize ( $, $); Frame.setlocationrelativeto (NULL);        Frame.setbackground (Color.gray); Frame.setvisible (true); }}
GridLayout Grid Layout Manager
 import java.awt.BorderLayout; import Java.awt.Button; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.GridLayout;/ * *gridlayout Grid Layout manager * / Public  class Test05 {     Public Static voidMain (string[] args) {Frame frame=NewFrame ("My Frame"); Button btn1=NewButton ("Button 1"); Button btn2=NewButton ("Button 2"); Button btn3=NewButton ("Button 3"); Button btn4=NewButton ("button 4"); Button btn5=NewButton ("button 5"); Button btn6=NewButton ("button 6"); Button btn7=NewButton ("button 7"); Frame.setlayout (NewGridLayout (0,2));//Set form to Grid layoutFrame.add (BTN1);        Frame.add (BTN2);        Frame.add (BTN3);        Frame.add (BTN4);        Frame.add (BTN5);        Frame.add (BTN6); Frame.add (BTN7,2);//Add component to specified grid, index starting from 0, component movingFrame.setsize ( $, $); Frame.setlocationrelativeto (NULL);        Frame.setbackground (Color.gray); Frame.setvisible (true); }}
CardLayout Card Layout Manager
 import java.awt.CardLayout; import java.awt.Color; import java.awt.Frame; import java.awt.Panel;/ * * CardLayout card layout Manager */ Public  class Test06 {     Public Static voidMain (string[] args) {Frame frame=NewFrame ("My Forms"); Panel pnl1=NewPanel (); Panel pnl2=NewPanel (); Panel pnl3=NewPanel (); CardLayout c=NewCardLayout ();//Create card layout managerFrame.setlayout (c);//setup form for card layoutPnl1.setbackground (color.red);        Pnl2.setbackground (Color.yellow); Pnl3.setbackground (Color.Blue);//Add a panel component to the form and specify a nameFrame.add (PNL1,"First"); Frame.add (PNL2,"Second"); Frame.add (PNL3,"Third"); C.last (frame);//Show last card, the last component addedC.previous (frame);//Show Previous cardC.show (Frame,"First");//Display a card with the name firstFrame.setsize ( -, -); Frame.setvisible (true); }}

Java Learning Notes (45)-Layout manager

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.