Studyon Minte9.com
Java SE




Grid Layout




package testexample; import java.awt.*; import javax.swing.*; import javax.swing.border.EmptyBorder; public class Test extends JFrame { public static void main(String[] args) { Test frame = new Test(); frame.setBounds(200, 200, 400, 200); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); //frame.setLayout(new BorderLayout()); frame.setVisible(true); } public Test() { JPanel main = new JPanel(); main.setBorder(new EmptyBorder(10, 30, 50, 100)); main.setLayout(new GridLayout(0, 3)); // any rows, 3 cols // --- Look Here --- // main.add(new JTextField("col 1")); main.add(new JTextField("col 2")); main.add(new JTextField("col 3")); main.add(new JButton("button 1")); main.add(new JButton("button 2")); main.add(new JButton("button 3")); main.getComponent(1).setPreferredSize(new Dimension(100, 20)); add(main, BorderLayout.NORTH); } }
 


http://docs.oracle.com/javase/tutorial/uiswing/layout/grid.html