1. 국경 레이아웃
2. FlowLayout
3. 그리드 레이아웃
4. BoxLayout
5. 빈 레이아웃 (null)
다른 레이아웃, 즉 Gridbaglayout과 Cardlayout도 있습니다.
참고 : JFrame 및 JDialog는 Borderlayout과 같은 레이아웃, JPanel 및 Applet은 FlowLayout과 같은 레이아웃입니다.
경계 레이아웃 샘플 코드 :
import java.awt.borderlayout; import javax.swing.jbutton; import javax.swing.jframe; public class borderlayoutexample을 jframe {jbutton btn1 = new jbutton ( "East"); JBUTTON BTN2 = 새로운 JBUTTON ( "South"); JBUTTON BTN3 = NEW JBUTTON ( "Western"); JBUTTON BTN4 = 새로운 JBUTTON ( "North"); JBUTTON BTN5 = NEW JBUTTON ( "Medium"); BorderLayoutExample () {init (); this.settitle ( "BorderLayout"); this.setResizable (true); this.setsize (200, 200); this.setLocationRelativeTo (null); this.setDefaultCloseOperation (exit_on_close); this.set -Visible (true); } void init () {this.setLayout (New BorderLayout (10,5)); // 기본값은 0, 0입니다. 수평 간격 10, 수직 간격 5 this.add (btn1, borderlayout.east); this.add (btn2, borderlayout.south); this.add (btn3, borderlayout.west); this.add (btn4, borderlayout.north); this.add (btn5, borderlayout.center); } public static void main (String args []) {new BorderLayoutexample (); }}실행 결과 :
스트리밍 레이아웃 샘플 코드 :
import java.awt.flowlayout; import javax.swing.jbutton; import javax.swing.jframe; public class flowlayoutexample을 jframe {jbutton btn1 = new jbutton ( "one"); JBUTTON BTN2 = 새로운 JBUTTON ( "2"); JBUTTON BTN3 = NEW JBUTTON ( "Three"); JBUTTON BTN4 = NEW JBUTTON ( "Four"); JBUTTON BTN5 = NEW JBUTTON ( "5"); FlowLayoutExample () {init (); this.settitle ( "flowLayout"); this.setResizable (true); this.setsize (200, 200); this.setLocationRelativeTo (null); this.setDefaultCloseOperation (exit_on_close); this.set -Visible (true); } void init () {this.setLayout (new FlowLayout (flowLayout.left, 10,5)); // 기본값은 중앙에 있습니다. 수평 간격 10, 수직 간격 5 this.add (btn1); this.add (btn2); this.add (btn3); this.add (btn4); this.add (btn5); } public static void main (String args []) {new FlowLayoutExample (); }}실행 결과 :
그리드 레이아웃 샘플 코드 :
import java.awt.gridlayout; import javax.swing.jbutton; import javax.swing.jframe; public class gridlayoutexample을 jframe {jbutton btn1 = new jbutton ( "One"); jbutton btn2 = New Jbutton ( "Two"); JBUTTON ( "3"); JBUTTON BTN4 = NEW JBUTTON ( "FOUR"); JBUTTON BTN5 = NEW JBUTTON ( "FIVE"); GRIDLAYOUTEXALLE () {init (); this.settitle ( "테이블 레이아웃"); this.setResizable (true); this.setsize (300, 200); this.setLocationRelativeTo (null); this.setDefaultCloseOperation (exit_on_close); this.setVisible (true);} void init () {this.setLayout (new GridLayout (2,3,10,5)); // 기본값은 1 행, N 열입니다. 2 행 및 3 개의 열, 수평 간격 10, 수직 간격 5 this.add (btn1); this.add (btn2); this.add (btn3); this.add (btn4); this.add (btn5);} public static void main (String args []) {new Gridlayoutexample ();}}실행 결과 :
박스 레이아웃 샘플 코드 :
import javax.swing.box; import javax.swing.boxlayout; import javax.swing.jbutton; import javax.swing.jframe; public class boxlayoutexample {jbutton btn1 = new jbutton ( "one"); jbutton btn2 = new new JButton ( "jbutton ="); JBUTTON ( "3"); JBUTTON BTN4 = NEW JBUTTON ( "FOUR"); JBUTTON BTN5 = NEW JBUTTON ( "5"); BoxLayoutExample () {init (); this.settitle ( "테이블 레이아웃"); this.setResizable (true); this.setsize (300, 200); this.setLocationRelativeTo (null); this.setDefaultCloseOperation (exit_on_close); this.setVisible (true);} void init () {this.setLayout (new BoxLayout (this.getContentPane (), boxLayout.x_axis)); // 대신 상자 컨테이너를 사용할 수 있습니다 // box box = new box (boxlayout.y_axis); box.add (btn ...); box.add (creat ..); this.add (btn1); this.add (btn2); this.getContentPane (). Add (box.createhorizontalStrut (10)); // X 레이아웃을 사용할 때는 고정 너비 구성 요소를 추가하여 //this.getContentPane ().add(box.createverticalStrut(5)); // Y 레이아웃을 사용할 때 고정 된 높이 구성 요소를 추가하여 this.add (btn3); this.add (btn4); this.add (btn5);} public static void main (String Args []) {New BoxLayoutExample ();}}실행 결과 :
빈 레이아웃 샘플 코드 :
import javax.swing.jbutton; import javax.swing.jframe; public class nulllayoutexample {jbutton btn1 = new jbutton ( "One"); jbutton btn2 = new Jbutton ( "Two"); Jbutton btn3 = new Jbutton ( "Three"); JBUTTON ( "4"); JBUTTON BTN5 = NEW JBUTTON ( "5"); NULLLAYOUTEXALLE () {init (); this.SetTitle ( "빈 레이아웃"); this.SetResizable (true); this.setsize (300, 300, 300); this.setLocationRelativeTo (null); this.setDefaultCloseOperation (exit_on_close); this.setVisible (true);} void init () {this.setLayout (null); btn1.setBounds (10, 0, 100, 50); // X 좌표 10, y 좌표 0, 구성 요소 너비 100, 높이 50BTN2. 세트 래운드 (20, 50, 100, 50); btn3.setbounds (30, 100, 100, 50); btn4. 세트 바운드 (40, 150, 100, 50); Btn5. 세트 밴드 (50, 200, 100, 50); Btn5. 세트 바운드 (50, 200, 10, 10, 10, 10, 50); this.add (btn1); this.add (btn2); this.add (btn3); this.add (btn4); this.add (btn5);} public static void main (string args []) {new nulllayoutexample ()}}실행 결과 :