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:Main.java

/** 
 * Creates a <code>JPanel</code> containing the given text placed in the
 * center as the only component.//from ww  w  . j  a v  a  2  s .co  m
 * @param text - the text to put on the panel
 * @return a JPanel containing only the given text
 */
public static JPanel makeTextPanel(String text) {
    JPanel panel = new JPanel(false);
    JLabel filler = new JLabel(text);
    filler.setHorizontalAlignment(SwingConstants.CENTER);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(filler);
    return panel;
}

From source file:Main.java

public Main() {
    super(new GridLayout(2, 2));
    add(new JButton("w w w.j a v a 2 s . c o m"));
    add(new JButton("w w w.j a v a 2 s . com"));
    add(new JButton("w w w.java2s.com"));
    add(new JButton("www.j ava 2 s . c o m"));
}

From source file:MainClass.java

public MainClass() {
    super(new GridLayout(2, 2));
    add(new JButton("w w w.j a v a 2 s . c o m"));
    add(new JButton("w w w.j a v a 2 s . com"));
    add(new JButton("w w w.java2s.com"));
    add(new JButton("www.j ava 2 s . c o m"));
}

From source file:Main.java

public Main() {
    super(new GridLayout(N, N));
    this.setPreferredSize(new Dimension(N * SIZE, N * SIZE));
    for (int i = 0; i < N * N; i++) {
        this.add(new ChessButton(i));
    }/*from   w  w  w  .ja  v a 2 s. co m*/
}

From source file:Main.java

public Main() {
    this.setLayout(new GridLayout(0, 1));
    this.add(new JLabel("Dialog close test.", JLabel.CENTER));
    this.add(new JButton(new AbstractAction("Close") {
        @Override//from   w w w. ja v  a  2s  .c o m
        public void actionPerformed(ActionEvent e) {
            Main.this.setVisible(false);
            Main.this.dispatchEvent(new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING));
        }
    }));
}

From source file:Main.java

public Main() {
    setLayout(new GridLayout(1, 2));
    String[] numbers = { "one", "two", "three", "four", "five", "six", "seven" };
    JList<String> list = new JList<>(numbers);
    list.setVisibleRowCount(1);//from  ww  w . j av  a  2  s.  c o m
    list.addListSelectionListener(this);
    JScrollPane s = new JScrollPane(list);
    s.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
    s.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    add(s);
    list.setSelectedIndex(3);
}

From source file:Main.java

public Main() {

    GridLayout g = new GridLayout(3, 3);
    pan = new JPanel(g);
    pan.add(new JButton("1"));
    pan.add(new JButton("2"));
    pan.add(new JButton("3"));
    pan.add(new JButton("4"));
    pan.add(new JButton("5"));
    pan.add(new JButton("6"));
    pan.add(new JButton("7"));
    pan.add(new JButton("8"));
    pan.add(new JButton("9"));
    JLabel l = new JLabel("grid layout");
    l.setHorizontalAlignment(SwingConstants.CENTER);

    setLayout(new BorderLayout());
    add(l, BorderLayout.NORTH);/* w ww  .  j a  v  a 2s .  c om*/
    add(pan, BorderLayout.CENTER);
    setSize(1000, 500);
    setVisible(true);
}

From source file:Main.java

public Main() {
    this.setLayout(new GridLayout(0, 1));
    this.add(new JLabel("Dialog event test.", JLabel.CENTER));
    this.add(new JButton(new AbstractAction("Close") {
        @Override//w  w w .  j  a v  a2  s .  co m
        public void actionPerformed(ActionEvent e) {
            Main.this.setVisible(false);
            Main.this.dispatchEvent(new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING));
        }
    }));
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println(e.paramString());
        }
    });
}

From source file:Main.java

public Main() {
    setLayout(new GridLayout(2, 1));
    add(pb);/*from   w  w  w .  j  av a 2 s.  c  o m*/
    sb.setValue(0);
    sb.setPaintTicks(true);
    sb.setMajorTickSpacing(20);
    sb.setMinorTickSpacing(5);
    sb.setBorder(new TitledBorder("Slide Me"));
    pb.setModel(sb.getModel()); // Share model
    add(sb);
}

From source file:MainClass.java

public MainClass() {
    setLayout(new BorderLayout());

    JPanel jp = new JPanel();
    jp.setLayout(new GridLayout(20, 20));
    int b = 0;/*from  ww w.j a  v  a2 s.c  om*/
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 20; j++) {
            jp.add(new JButton("Button " + b));
            ++b;
        }
    }

    // Add panel to a scroll pane.
    int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(jp, v, h);

    // Add scroll pane to the content pane.
    add(jsp, BorderLayout.CENTER);

}