List of usage examples for java.awt GridLayout GridLayout
public GridLayout(int rows, int cols)
From source file:GridLayoutTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("GridLayout Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 2)); frame.add(new JButton("Button 1")); frame.add(new JButton("Button 2")); frame.add(new JButton("Button 3")); frame.add(new JButton("Button 4")); frame.add(new JButton("Button 5")); frame.add(new JButton("Button 6")); frame.add(new JButton("Button 7")); frame.add(new JButton("Button 8")); frame.pack();//from www.j a v a2 s.c om frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(2, 2)); JLabel label = new JLabel("User Name:", SwingConstants.RIGHT); JLabel label2 = new JLabel("Password:", SwingConstants.RIGHT); JTextField userNameField = new JTextField(20); JPasswordField passwordField = new JPasswordField(); frame.add(label);/* ww w. jav a 2s .co m*/ frame.add(userNameField); frame.add(label2); frame.add(passwordField); frame.setSize(200, 70); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 300);/*from ww w . j a v a2 s. c om*/ JPanel panel = new JPanel(new GridLayout(3, 1)); JLabel label = new JLabel(); JTextField tf = new JTextField(); JButton b = new JButton("calc sting width"); b.addActionListener(e -> { FontMetrics fm = label.getFontMetrics(label.getFont()); String text = tf.getText(); int textWidth = fm.stringWidth(text); label.setText("text width for \"" + text + "\": " + textWidth); }); panel.add(label); panel.add(tf); panel.add(b); frame.setContentPane(panel); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(2, 2)); JLabel label = new JLabel("User Name:", SwingConstants.RIGHT); JLabel label2 = new JLabel("Password:", SwingConstants.RIGHT); JTextField userNameField = new JTextField(20); JPasswordField passwordField = new JPasswordField(); passwordField.setEchoChar('#'); frame.add(label);// w ww . java 2 s . co m frame.add(userNameField); frame.add(label2); frame.add(passwordField); frame.setSize(200, 70); frame.setVisible(true); }
From source file:AlignmentSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(0, 1)); JTextField textField = new JTextField("Left"); textField.setHorizontalAlignment(JTextField.LEFT); content.add(textField);/*w ww . j ava 2 s. c om*/ textField = new JTextField("Center"); textField.setHorizontalAlignment(JTextField.CENTER); content.add(textField); textField = new JTextField("Right"); textField.setHorizontalAlignment(JTextField.RIGHT); content.add(textField); textField = new JTextField("Leading"); textField.setHorizontalAlignment(JTextField.LEADING); content.add(textField); textField = new JTextField("Trailing"); textField.setHorizontalAlignment(JTextField.TRAILING); content.add(textField); frame.pack(); frame.setSize(250, (int) frame.getSize().getHeight()); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JLabel label = new JLabel(new ElliptIcon(380, 260, Color.red)); label.setLayout(new GridLayout(2, 2)); frame.setContentPane(label);//w w w. j a v a 2s.c om for (int i = 0; i < 4; i++) { label.add(new JLabel(new ElliptIcon(100, 60, Color.blue))); } frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:MnemonicSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Mnemonics"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(1, 0)); JButton button1 = new JButton("Warning"); button1.setMnemonic(KeyEvent.VK_W); content.add(button1);/*from w w w . j a v a 2 s . c om*/ JButton button2 = new JButton("Warning"); button2.setMnemonic(KeyEvent.VK_H); content.add(button2); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Cycle Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 3)); for (int i = 0; i < 3; i++) { JButton button = new JButton("" + i); frame.add(button);//from www .j a v a 2 s . co m } JPanel panel = new JPanel(); panel.setFocusCycleRoot(true); panel.setFocusTraversalPolicyProvider(true); panel.setLayout(new GridLayout(1, 3)); for (int i = 0; i < 3; i++) { JButton button = new JButton("" + (i + 3)); panel.add(button); } frame.add(panel); for (int i = 0; i < 3; i++) { JButton button = new JButton("" + (i + 6)); frame.add(button); } frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String title = (args.length == 0 ? "TextArea Example" : args[0]); JFrame frame = new JFrame(title); Container content = frame.getContentPane(); content.setLayout(new GridLayout(0, 2)); JTextArea leftTextArea = new JTextArea(); content.add(leftTextArea);/*from w w w .j a va2 s .c o m*/ leftTextArea.paste(); JTextArea rightTextArea = new JTextArea() { public boolean isManagingFocus() { return false; } }; rightTextArea.paste(); JScrollPane rightPane = new JScrollPane(rightTextArea); content.add(rightPane); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new GridLayout(N, N)); for (int i = 0; i < N * N; i++) { frame.add(new CirclePanel()); }//from w w w.j av a2 s . co m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }