Example usage for java.awt GridLayout GridLayout

List of usage examples for java.awt GridLayout GridLayout

Introduction

In this page you can find the example usage for java.awt GridLayout GridLayout.

Prototype

public GridLayout(int rows, int cols) 

Source Link

Document

Creates a grid layout with the specified number of rows and columns.

Usage

From source file:Test.java

public Test() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel1 = new JPanel(new GridLayout(1, 5));
    for (int i = 0; i < 5; i++) {
        panel1.add(new JLabel("Left " + i));
    }//from   www  . j  a  va 2 s .  c  o  m
    panel1.setPreferredSize(new Dimension(250, 50));

    JPanel panel2 = new JPanel(new GridLayout(1, 5));
    for (int i = 0; i < 5; i++) {
        panel2.add(new JLabel("Right " + i));
    }
    panel2.setPreferredSize(new Dimension(250, 50));

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, panel2);
    split.setContinuousLayout(true);
    getContentPane().add(split, BorderLayout.CENTER);
    pack();
    setSize(500, 100);
}

From source file:Main.java

public Main() {
    setLayout(new GridLayout(6, 1));
    add(new JButton("A"));
    add(new JButton("D"));

    add(new JButton("C"));

    add(new JButton("E"));
    add(new JButton("B"));
    add(new JButton("F"));
}

From source file:Main.java

public Main() {
    super(new GridLayout(1, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon icon = createImageIcon("images/middle.gif");

    JComponent panel1 = makeTextPanel("Panel #1");
    tabbedPane.addTab("Tab 1", icon, panel1, "Does nothing");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    JComponent panel2 = makeTextPanel("Panel #2");
    tabbedPane.addTab("Tab 2", icon, panel2, "Does twice as much nothing");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    JComponent panel3 = makeTextPanel("Panel #3");
    tabbedPane.addTab("Tab 3", icon, panel3, "Still does nothing");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    JComponent panel4 = makeTextPanel("Panel #4 (has a preferred size of 410 x 50).");
    panel4.setPreferredSize(new Dimension(410, 50));
    tabbedPane.addTab("Tab 4", icon, panel4, "Does nothing at all");
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);

    add(tabbedPane);/*from w  ww .  j  a v  a 2s. c  o m*/

    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}

From source file:BoxLayoutGlueStrutCompare.java

public BoxLayoutGlueStrutCompare() {
    JPanel p = new JPanel(new GridLayout(3, 1));

    JPanel p1 = new JPanel();
    Box box1 = new Box(BoxLayout.X_AXIS);
    box1.add(Box.createHorizontalGlue());
    box1.add(new JButton("glue-strut"));
    box1.add(Box.createHorizontalStrut(15));
    box1.add(new JButton("strut-glue"));
    box1.add(Box.createHorizontalGlue());
    p1.add(box1);//from   w  ww. j a  va2s.c o m
    p1.setBorder(BorderFactory.createRaisedBevelBorder());

    JPanel p2 = new JPanel();
    Box box2 = new Box(BoxLayout.X_AXIS);
    box2.add(Box.createHorizontalStrut(25));
    box2.add(new JButton("strut-glue"));
    box2.add(Box.createHorizontalGlue());
    box2.add(new JButton("glue-strut"));
    box2.add(Box.createHorizontalStrut(25));
    p2.add(box2);
    p2.setBorder(BorderFactory.createRaisedBevelBorder());

    JPanel p3 = new JPanel();
    Box box3 = new Box(BoxLayout.X_AXIS);
    box3.add(Box.createHorizontalStrut(25));
    box3.add(new JButton("strut-glue"));
    box3.add(Box.createHorizontalGlue());
    box3.add(new JButton("glue-glue"));
    box3.add(Box.createHorizontalGlue());
    p3.add(box3);
    p3.setBorder(BorderFactory.createRaisedBevelBorder());

    p.add(p1);
    p.add(p2);
    p.add(p3);
    getContentPane().add(p);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
}

From source file:Main.java

public Main() {
    this.setLayout(new GridLayout(0, 1));
    this.add(label);
    this.add(new JButton(new AbstractAction("OK") {

        @Override/*from  www.  java  2 s . c  o  m*/
        public void actionPerformed(ActionEvent e) {
            JButton b = (JButton) e.getSource();
            b.setText("123");
        }
    }));
    new Timer(100, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            label.setText(String.valueOf(System.nanoTime()));
        }
    }).start();
}

From source file:FocusTraversalExample.java

public FocusTraversalExample() {
    setLayout(new GridLayout(6, 1));
    add(new JButton("A"));
    add(new JButton("D"));

    add(new JButton("C"));

    add(new JButton("E"));
    add(new JButton("B"));
    add(new JButton("F"));
}

From source file:GridSizeTest.java

public GridSizeTest() {
    Container pane = getContentPane();
    pane.setLayout(new GridLayout(2, 2));
    JButton button = new JButton("First");
    pane.add(button);/*from w  ww .j  av a2s  . c om*/
    button = new JButton("Second with a very long name");
    pane.add(button);
    button = new JButton("Hi");
    button.setFont(new Font("Courier", Font.PLAIN, 36));
    pane.add(button);
    button = new JButton("There");
    pane.add(button);
}

From source file:BevelExample.java

public BevelExample() {
    super(true);/*from   w ww . ja  v  a  2 s.  c o  m*/
    setLayout(new GridLayout(1, 4));

    bevel = new BevelBorder(BevelBorder.RAISED);
    empty = new EmptyBorder(5, 5, 5, 5);

    label[0] = new JLabel("Home");
    label[1] = new JLabel("Back");
    label[2] = new JLabel("Forward");
    label[3] = new JLabel("Stop");

    for (int i = 0; i < label.length; i++) {
        label[i].setHorizontalAlignment(JLabel.CENTER);
        label[i].addMouseListener(new RolloverListener());
        label[i].setBorder(empty);
        add(label[i]);
    }
}

From source file:GridTest.java

public GridTest(int rows, int cols) {
    Container pane = getContentPane();
    pane.setLayout(new GridLayout(rows, cols));
    for (int i = 0; i < 20; i++) {
        JButton button = new JButton(Integer.toString(i + 1));
        pane.add(button);//w  ww.j a  v a 2s. c o  m
    }
}

From source file:Main.java

public Main() {
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setLayout(new GridLayout(2, 0));

    Container contentPane = this.getContentPane();
    contentPane.add(nameLabel);/*from w  w  w.j  a  v  a  2  s .  c  om*/
    contentPane.add(name);
    contentPane.add(mirroredNameLabel);
    contentPane.add(mirroredName);

    Document nameModel = name.getDocument();
    mirroredName.setDocument(nameModel);

    pack();
    setVisible(true);
}