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 static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel(new GridLayout(10, 10, 10, 10));

    for (int i = 0; i < 100; i++) {
        panel.add(new JButton(String.valueOf(i)));
    }/*w  w w . j  ava 2 s  . c  o  m*/

    frame.add(panel);

    frame.setSize(600, 600);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new GridLayout(0, 1, 5, 5));

    String[] speciesName = { "1", "2", "3" };
    String[][] breedName = { { "A", "P", "A" }, { "B", "P", "S" }, { "DDo", "A", "P" } };
    JComboBox<String> petSpecies = new JComboBox<>(speciesName);
    JComboBox<String> petBreed = new JComboBox<>();
    petSpecies.addItemListener(e -> {
        int ii = petSpecies.getSelectedIndex();
        ComboBoxModel cbm = new DefaultComboBoxModel(breedName[ii]);
        petBreed.setModel(cbm);//w w w  .  jav a2 s.com
        petBreed.requestFocusInWindow();
    });
    gui.add(petSpecies);
    gui.add(petBreed);

    JOptionPane.showMessageDialog(null, gui);
}

From source file:TryGridLayout.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Grid Layout");
    aWindow.setBounds(30, 30, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GridLayout grid = new GridLayout(3, 4, 30, 20);
    Container content = aWindow.getContentPane();
    content.setLayout(grid);//from w  w  w  .  j  a va 2 s.c o m
    JButton button = null;
    for (int i = 1; i <= 10; i++) {
        content.add(button = new JButton(" Press " + i));
    }
    aWindow.pack();
    aWindow.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Integer[] numbers = { 1, 2, 3 };
    String[] names = { "A", "B", "C" };
    JComboBox numberCombo = new JComboBox(numbers);
    JComboBox nameCombo = new JComboBox(names);
    JPanel p = new JPanel(new GridLayout(0, 1, 3, 3));
    p.add(numberCombo);/*from  w  w w.j  av  a2  s  .c  om*/
    p.add(nameCombo);

    JOptionPane.showMessageDialog(null, p);

    Integer chosenNumber = (Integer) numberCombo.getSelectedItem();
    System.out.println("Chosen Number: " + chosenNumber);
    String chosenName = (String) nameCombo.getSelectedItem();
    System.out.println("Chosen Name: " + chosenName);
}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridLayout(1, 2, 2, 2));

    JTextArea tArea1 = new JTextArea();
    tArea1.setLineWrap(true);// w  w  w . ja  va  2 s  .com
    JTextArea tArea2 = new JTextArea();
    tArea2.setLineWrap(true);
    tArea1.setText("I got a long long line of text in my JTextArea");
    tArea2.setText("I got a long long line of text in my JTextArea");

    JScrollPane scroller1 = new JScrollPane();
    JScrollPane scroller2 = new JScrollPane();
    scroller1.setViewportView(tArea1);
    scroller2.setViewportView(tArea2);

    contentPane.add(scroller1);
    contentPane.add(scroller2);

    frame.setContentPane(contentPane);
    frame.setSize(100, 100);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(5, 5));

    int sz = 4;//from w  w  w. ja  va  2  s  . c  om
    Container content = new JPanel(new GridLayout(sz, 0, 2, 2));
    for (int f = 0; f < sz * sz; f++) {
        content.add(new JButton());
    }
    gui.add(content, BorderLayout.CENTER);

    Container info = new JPanel(new FlowLayout(FlowLayout.CENTER, 50, 5));
    info.add(new JLabel("Flow"));
    info.add(new JLabel("Layout"));
    gui.add(info, BorderLayout.PAGE_START);

    gui.add(new JLabel("Label"), BorderLayout.LINE_END);

    JOptionPane.showMessageDialog(null, gui);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new GridLayout(2, 2, 10, 10));

    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    frame.add(button1);/*from www  .  j  av a 2s . co m*/

    JButton button2 = new JButton("warn");
    frame.add(button2);

    JButton button3 = new JButton("Warning");
    frame.add(button3);

    String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
            + "<font color=\"#FF0080\"><u>Multi-line</u></font>";
    JButton button4 = new JButton(htmlButton);
    frame.add(button4);

    JRootPane rootPane = frame.getRootPane();
    rootPane.setDefaultButton(button2);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    UIManager.put("ProgressBar.repaintInterval", 100);
    UIManager.put("ProgressBar.border", BorderFactory.createLineBorder(Color.blue, 2));
    JFrame f = new JFrame();
    f.setLayout(new GridLayout(0, 1, 5, 5));
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(createBar());/*  w  w w . j ava 2  s .  com*/
    f.add(createBar());
    f.add(createBar());
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel ui = new JPanel(new BorderLayout(20, 20));

    ui.setBorder(new LineBorder(Color.RED, 1));

    JTextField fileName = new JTextField();
    ui.add(fileName, BorderLayout.NORTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 0, 10, 30));
    ui.add(buttonPanel, BorderLayout.CENTER);

    JButton creater = new JButton("Create File");
    buttonPanel.add(creater);/*from   w ww .j a va  2 s. com*/
    JButton deleter = new JButton("Delete File");
    buttonPanel.add(deleter);

    JOptionPane.showMessageDialog(null, ui);

}

From source file:Main.java

public static void main(String[] args) {
    JTextField[] txtAllAverages;//from  w  w w  . ja v  a 2 s . c  o m
    int testCount = 2;

    txtAllAverages = new JTextField[testCount];

    JPanel inputControls = new JPanel(new BorderLayout(5, 5));

    JPanel inputControlsLabels = new JPanel(new GridLayout(0, 1, 3, 3));
    JPanel inputControlsFields = new JPanel(new GridLayout(0, 1, 3, 3));
    inputControls.add(inputControlsLabels, BorderLayout.WEST);
    inputControls.add(inputControlsFields, BorderLayout.CENTER);
    for (int i = 0; i < testCount; i++) {
        inputControlsLabels.add(new JLabel("Test score: "));
        JTextField field = new JTextField(10);
        inputControlsFields.add(field);
        txtAllAverages[i] = field;
    }

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2));

    controls.add(new JButton("Reset"));
    controls.add(new JButton("Submit"));

    JPanel gui = new JPanel(new BorderLayout(10, 10));
    gui.setBorder(new TitledBorder("Averages"));
    gui.add(inputControls, BorderLayout.CENTER);
    gui.add(controls, BorderLayout.SOUTH);

    JFrame f = new JFrame();
    f.setContentPane(gui);

    f.pack();
    f.setLocationByPlatform(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}