1. Layout da fronteira
2. FlowLayout
3. Layout da grade
4. Boxlayout
5. Layout vazio (nulo)
Existem também dois outros layouts, ou seja, Gridbaglayout e Cardlayout
Nota: JFrame e JDialog são layouts como BorderLayout, JPanel e Applet são layouts como FlowLayout
Layout de limite Código de amostra:
importar java.awt.borderlayout; importar javax.swing.jbutton; importar javax.swing.jframe; public class BorderLayoutExample estende jframe {jbutton btn1 = new jbutton ("leste"); Jbutton btn2 = novo jbutton ("sul"); Jbutton btn3 = novo jbutton ("ocidental"); Jbutton btn4 = novo jbutton ("norte"); Jbutton btn5 = new jbutton ("médio"); BorderLayoutExample () {init (); this.settitle ("borderlayout"); this.setResizable (true); this.SetSize (200, 200); this.setLocationRelativeTo (NULL); this.setDefaultCloseoperation (exit_on_close); this.setVisible (true); } void init () {this.setLayout (new BorderLayout (10,5)); // O padrão é 0, 0; espaçamento horizontal 10, espaçamento vertical 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 (); }}Resultados em execução:
Código de amostra de layout de streaming:
importar java.awt.flowlayout; importar javax.swing.jbutton; importar javax.swing.jframe; public class FlowLayoutExample estende jframe {jbutton btn1 = new jbutton ("um"); Jbutton btn2 = new jbutton ("dois"); Jbutton btn3 = new jbutton ("três"); Jbutton btn4 = new jbutton ("quatro"); Jbutton btn5 = new jbutton ("cinco"); FlowLayoutExample () {init (); this.setTitle ("FlowLayout"); this.setResizable (true); this.SetSize (200, 200); this.setLocationRelativeTo (NULL); this.setDefaultCloseoperation (exit_on_close); this.setVisible (true); } void init () {this.setLayout (new FlowLayout (flowlayout.left, 10,5)); // O padrão está centrado; Espaçamento horizontal 10, espaçamento vertical 5 this.Add (BTN1); this.add (btn2); this.add (btn3); this.add (btn4); this.add (BTN5); } public static void main (string args []) {new FlowLayoutExample (); }}Resultados em execução:
Código de amostra de layout da grade:
importar java.awt.gridlayout; importar javax.swing.jbutton; importar javax.swing.jframe; public class GridLayoutExample estende JFrame {Jbutton btn1 = New Jbutton ("One"); Jbutton ("três"); jbutton btn4 = new jbutton ("quatro"); jbutton btn5 = new jbutton ("cinco"); gridlayoutExample () {init (); this.setTitle ("Layout da tabela"); this.setResizable (true); this.SetSize (300, 200); this.setLocationRelativeTo (NULL); this.setDefaultCloseoperation (exit_on_close); this.setVisible (true);} void init () {this.setLayout (novo gridlayout (2,3,10,5)); // O padrão é 1 linha, n colunas; 2 linhas e 3 colunas, espaçamento horizontal 10, espaçamento vertical 5This.Add (BTN1); this.add (btn2); this.add (btn3); this.add (btn4); this.add (btn5);} public static void main (string args []) {new GridLayoutExample ();}}Resultados em execução:
Código de amostra de layout da caixa:
importar javax.swing.box; importar javax.swing.boxlayout; importar javax.swing.jbutton; importar javax.swing.jframe; classe pública boxlayoutExample estende jframe {jbutton btn1 = novo jbutton ("" One "); Jbutton ("três"); jbutton btn4 = new jbutton ("quatro"); jbutton btn5 = new jbutton ("cinco"); boxlayoutExample () {init (); this.setTitle ("Layout da tabela"); 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); // você pode usar o contêiner da caixa // caixa da caixa = novo Box (boxlayout.y_axis); box.add (btn ...); box.add (creat ..); this.add (btn1); this.add (btn2); this.getContentPane (). Add (box.createHorizontalTrut (10)); // Ao usar o layout X, adicione componentes de largura fixa para separar //this.getContentPane().add(Box.CreateverticStrut(5)); // Ao usar o layout y, adicione componentes de altura fixa para separar isso.Resultados em execução:
Código de amostra de layout vazio:
importar javax.swing.jbutton; importar javax.swing.jframe; public classe nulllayoutExample estende jframe {jbutton btn1 = new jbutton ("one"); jbutton btn2 = new jbutton ("dois"); jbutton; Jbutton ("quatro"); jbutton btn5 = new jbutton ("cinco"); nulllayoutExample () {init (); this.settitle ("layout vazio"); this.setResizable (true); this.SetSize (300, 300. // x coordenada 10, y coordenada 0, largura do componente 100, altura 50BTN2.fase (20, 50, 100, 50); btn3.fase de limpeza (30, 100, 50, 50); btn4.fase, 50, 50, 50, 50, 150, 100, 50); Btn. 50); this.Resultados em execução: