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, int hgap, int vgap) 

Source Link

Document

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

Usage

From source file:Main.java

public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));

    simplePanel.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Title Lowered Etched Border"));
    simplePanel.add(new JLabel("Examples"), JLabel.CENTER);

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

From source file:Main.java

public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));

    simplePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLUE),
            "Title Line Border with color"));
    simplePanel.add(new JLabel("Examples"), JLabel.CENTER);

    add(simplePanel);//from  w  w w.j  ava  2s. c  o  m
}

From source file:Main.java

public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));

    simplePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),
            BorderFactory.createLoweredBevelBorder()));
    simplePanel.add(new JLabel("Examples"), JLabel.CENTER);

    add(simplePanel);/*from  ww  w. j  a  va 2  s  .  c om*/
}

From source file:Main.java

public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));

    JLabel lineBorderLabel = new JLabel("Line Border", JLabel.CENTER);
    lineBorderLabel.setBorder(BorderFactory.createLineBorder(Color.black));
    simplePanel.add(lineBorderLabel);/*from  ww w.jav a2 s .  c  o m*/

    add(simplePanel);
}

From source file:Main.java

public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
    ImageIcon icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage("matte.gif"));
    simplePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
            BorderFactory.createMatteBorder(-1, -1, -1, -1, icon)));
    simplePanel.add(new JLabel("Examples"), JLabel.CENTER);

    add(simplePanel);// ww  w. jav a  2 s  .  c om
}

From source file:Main.java

public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));

    JLabel bevelRasBorderLabel = new JLabel("Raised Bevel Border", JLabel.CENTER);
    bevelRasBorderLabel.setBorder(BorderFactory.createRaisedBevelBorder());
    simplePanel.add(bevelRasBorderLabel);

    add(simplePanel);//  w  ww. j a v a2s . c  o  m
}

From source file:Main.java

public Main() {
    super("JLabel Demo");
    setSize(600, 100);/*from www.j a v  a2  s .c o m*/

    JPanel content = new JPanel(new GridLayout(1, 4, 4, 4));

    JLabel label = new JLabel("Java2s");
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s", SwingConstants.CENTER);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s");
    label.setFont(new Font("Helvetica", Font.BOLD, 18));
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    ImageIcon image = new ImageIcon("java2sLogo.gif");
    label = new JLabel("Java2s", image, SwingConstants.RIGHT);
    label.setVerticalTextPosition(SwingConstants.TOP);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    getContentPane().add(content);
    setVisible(true);
}

From source file:LabelDemo.java

public LabelDemo() {
    super("JLabel Demo");
    setSize(600, 100);/*from   ww  w  . j  a  v  a 2 s .  co  m*/

    JPanel content = new JPanel(new GridLayout(1, 4, 4, 4));

    JLabel label = new JLabel("Java2s");
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s", SwingConstants.CENTER);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    label = new JLabel("Java2s");
    label.setFont(new Font("Helvetica", Font.BOLD, 18));
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    ImageIcon image = new ImageIcon("java2sLogo.gif");
    label = new JLabel("Java2s", image, SwingConstants.RIGHT);
    label.setVerticalTextPosition(SwingConstants.TOP);
    label.setOpaque(true);
    label.setBackground(Color.white);
    content.add(label);

    getContentPane().add(content);
    setVisible(true);
}

From source file:Main.java

public Main() {
    jPanel1.setLayout(new GridLayout(0, 2, 10, 10));
    jButton1.addActionListener(e -> {
        JCheckBox cb = new JCheckBox("New CheckBox");
        jPanel1.add(cb);/*  w ww .j a  v  a  2s.c  om*/
        jPanel1.revalidate();
        jPanel1.repaint();
    });
    frame.add(jScrollPane1);
    frame.add(jButton1, BorderLayout.SOUTH);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    int rows = BTN_LABELS.length;
    int cols = BTN_LABELS[0].length;
    int gap = 4;/*from w  ww .  ja  v a2s . c o  m*/
    mainPanel.setBorder(BorderFactory.createEmptyBorder(gap, gap, gap, gap));
    mainPanel.setLayout(new GridLayout(rows, cols, gap, gap));
    for (String[] btnLabelRow : BTN_LABELS) {
        for (String btnLabel : btnLabelRow) {
            JButton btn = createButton(btnLabel);
            mainPanel.add(btn);
        }
    }
}