1. تخطيط الحدود
2. FlowLayout
3. تخطيط الشبكة
4. boxlayout
5. تخطيط فارغ (لاغ)
هناك أيضًا تخطيطان آخران ، وهما Gridbaglayout و cardlayout
ملاحظة: Jframe و JDialog هي تخطيطات مثل BorderLayout و JPanel و Applet هي تخطيطات كـ FlowLayout
رمز نموذج تخطيط الحدود:
استيراد java.awt.borderlayout ؛ import javax.swing.jbutton ؛ استيراد javax.swing.jframe ؛ public class borderlayoutexample يمتد Jframe {jbutton btn1 = new jbutton ("east") ؛ jbutton btn2 = new jbutton ("south") ؛ jbutton btn3 = new jbutton ("Western") ؛ jbutton btn4 = new jbutton ("north") ؛ jbutton btn5 = new jbutton ("متوسطة") ؛ BorderLayoutexample () {init () ؛ this.settitle ("BorderLayout") ؛ this.setResible (صحيح) ؛ this.setsize (200 ، 200) ؛ this.setLocationRelativeto (null) ؛ this.setDefaultCloseOperation (exit_on_close) ؛ this.setVisible (صحيح) ؛ } 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 () ؛ }}نتائج التشغيل:
دفق رمز نموذج تخطيط:
استيراد java.awt.flowlayout ؛ import javax.swing.jbutton ؛ استيراد javax.swing.jframe ؛ الطبقة العامة flowlayoutexample تمتد jframe {jbutton btn1 = new jbutton ("One") ؛ jbutton btn2 = new jbutton ("two") ؛ jbutton btn3 = New Jbutton ("Three") ؛ jbutton btn4 = new jbutton ("Four") ؛ jbutton btn5 = new jbutton ("Five") ؛ FlowLayoutexample () {init () ؛ this.settitle ("FlowLayout") ؛ this.setResible (صحيح) ؛ this.setsize (200 ، 200) ؛ this.setLocationRelativeto (null) ؛ this.setDefaultCloseOperation (exit_on_close) ؛ this.setVisible (صحيح) ؛ } 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 () ؛ }}نتائج التشغيل:
رمز نموذج تخطيط الشبكة:
استيراد java.awt.gridlayout ؛ استيراد javax.swing.jbutton ؛ استيراد javax.swing.jframe BTN4 = New JButton ("Four") ؛ jbutton btn5 = New JButton ("Five") ؛ GridLayoutExample () {init () ؛ this.settitle ("تصميم الجدول") ؛ this.setResible (صحيح) ؛ 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)) ؛ // الافتراضي هو صف واحد ، N الأعمدة ؛ 2 صفوف و 3 أعمدة ، التباعد الأفقي 10 ، التباعد العمودي 5THIS.ADD (BTN1) ؛ this.Add (BTN2) ؛ this.Add (BTN3) ؛ this.add (BTN4) ؛ this.add (btn5) ؛} الفراغ الثابت العام (args string []) {new GridLayoutexample () ؛}}نتائج التشغيل:
رمز نموذج تخطيط المربع:
استيراد javax.swing.box ؛ import javax.swing.boxlayout ؛ import javax.swing.jbutton ؛ import javax.swing.jframe ؛ public class boxlayoutexample تمتد jframe {jbutton btn1 = jbutton ("واحد") ؛ JButton ("Three") ؛ Jbutton Btn4 = New JButton ("Four") ؛ Jbutton BTN5 = New JButton ("Five") ؛ BoxLayOutExample () {init () ؛ this.settitle ("تصميم الجدول") ؛ this.setResible (صحيح) ؛ 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 (boxlayout.y_axis) ؛ box.add (btn ...) ؛ box.add (creat ..) ؛ this.add (btn1) ؛ this.add (btn2) ؛ this.getContentPane (). add (box.createhorizontalstrut (10)) ؛ // عند استخدام X Layout ، أضف مكونات العرض الثابتة لفصل //this.getContentPane().Add(box.createverticalstrut(5)) ؛ // عند استخدام تخطيط y ، أضف مكونات الارتفاع الثابتة لفصل this.add (btn3) ؛ this.add (btn4) ؛ this.add (btn5) ؛} الفراغ الثابت العام (سلسلة args []) {new boxlayoutexample () ؛}}نتائج التشغيل:
رمز نموذج التخطيط الفارغ:
استيراد javax.swing.jbutton ؛ استيراد javax.swing.jframe ؛ الطبقة العامة nulllayoutexample تمتد jframe {jbutton btn1 = new jbutton ("واحد") jbutton ("Four") ؛ jbutton btn5 = new jbutton ("Five") ؛ nulllayoutexample () {init () ؛ this.Settitle ("تخطيط فارغ") ؛ هذا. 300) ؛ this.setLocationRelativeto (null) ؛ this.setDefaultCloseOperation (exit_on_close) ؛ this.setVisible (true) ؛} void init () {this.setLayout (null) ؛ btn1.setBounds (10 ، 0 ، 100 ، 50) ؛ . 50) ؛ this.Add (btn1) ؛ this.add (btn2) ؛ this.add (btn3) ؛ this.add (btn4) ؛ this.add (btn5) ؛} الفراغ الثابت العام (args args [])نتائج التشغيل: