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() 

Source Link

Document

Creates a grid layout with a default of one column per component, in a single row.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTextField account = new JTextField(10);
    JPanel accountPanel = new JPanel(new GridLayout());
    accountPanel.add(account);/*from  w  ww. j a  va2  s .com*/
    accountPanel.setBorder(new TitledBorder("Account"));

    String[] firstDigitList = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

    JLabel firstDigitListLabel = new JLabel("Leading Digit Change");
    JPanel firstDigitListPanel = new JPanel(new BorderLayout(4, 2));
    firstDigitListPanel.add(firstDigitListLabel, BorderLayout.WEST);
    JComboBox firstDigitCombo = new JComboBox(firstDigitList);
    firstDigitListPanel.add(firstDigitCombo);
    firstDigitCombo.setSelectedIndex(0);
    firstDigitListPanel.setBorder(new TitledBorder("LDC"));

    JPanel panel = new JPanel();
    panel.add(accountPanel);
    panel.add(firstDigitListPanel);

    int result = JOptionPane.showConfirmDialog(null, panel, "Please Enter Values",
            JOptionPane.OK_CANCEL_OPTION);
}

From source file:Main.java

public static void main(String[] args) {
    int specificX = 40;
    int specificY = 20;

    JPanel gui = new JPanel(new BorderLayout());
    JTextField tf = new JTextField(10);
    JPanel borderPanel = new JPanel(new GridLayout());
    borderPanel.add(tf);/*from   w w  w . ja v  a2 s .  co  m*/
    borderPanel.setBorder(new EmptyBorder(specificX, specificY, specificX, specificY));
    borderPanel.setBackground(Color.GREEN);
    gui.add(borderPanel);

    JOptionPane.showMessageDialog(null, gui);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    final MaskFormatter formatter = new TimeFormatter();
    formatter.setValueClass(java.util.Date.class);
    final JFormattedTextField tf2 = new JFormattedTextField(formatter);
    tf2.setValue(new Date());
    final JLabel label = new JLabel();
    JButton bt = new JButton("Show Value");
    bt.addActionListener(e -> {/*from   w w  w  .j ava  2s  .  c o  m*/
        System.out.println(" value 2 = " + tf2.getValue());
        System.out.println(" value 2 = " + tf2.getText());
        System.out.println("value class: " + formatter.getValueClass());
        label.setText(tf2.getText());
    });
    JFrame f = new JFrame();
    f.getContentPane().setLayout(new GridLayout());
    f.getContentPane().add(tf2);
    f.getContentPane().add(label);
    f.getContentPane().add(bt);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel ui = new JPanel(new BorderLayout(4, 4));
    ui.setBorder(new EmptyBorder(6, 6, 6, 6));

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEADING));
    ui.add(controls, BorderLayout.PAGE_START);
    int s = 100;//from  ww w.  ja va  2s . c om
    Dimension[] sizes = { new Dimension(s * 4, s * 2), new Dimension(s * 6, s * 3),
            new Dimension(s * 8, s * 4) };
    final JComboBox cb = new JComboBox(sizes);
    controls.add(cb);
    final JPanel[] panels = new JPanel[sizes.length];
    for (int ii = 0; ii < sizes.length; ii++) {
        Dimension d = sizes[ii];
        BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
        JPanel p = new JPanel(new GridLayout());
        JLabel l = new JLabel(new ImageIcon(bi));
        p.add(l);
        panels[ii] = p;
    }
    ItemListener sizeListener = new ItemListener() {

        JPanel current = panels[0];

        @Override
        public void itemStateChanged(ItemEvent e) {
            JPanel next = panels[cb.getSelectedIndex()];
            swapComponentsAndResizeUI(ui, current, next);
            current = next;
        }
    };
    cb.addItemListener(sizeListener);

    ui.add(panels[0], BorderLayout.CENTER);

    JFrame f = new JFrame("Three Sized Panels");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(ui);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}

From source file:Main.java

public Main() {
    super(new GridLayout());
    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() {

    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"));

    GridLayout gridLayout = new GridLayout();

    setLayout(gridLayout);/*from ww  w  .ja v  a 2s  .  c  om*/

    System.out.println(gridLayout.getColumns());
}

From source file:Main.java

public Main() {

    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"));

    GridLayout gridLayout = new GridLayout();

    setLayout(gridLayout);//from  www  .jav  a  2 s .  c o m

    System.out.println(gridLayout.preferredLayoutSize(this));
}

From source file:Main.java

public Main() {

    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"));

    GridLayout gridLayout = new GridLayout();

    setLayout(gridLayout);/*from  w  w w  .  j  a va  2s  . co  m*/

    System.out.println(gridLayout.getVgap());
}

From source file:Main.java

public Main() {

    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"));

    GridLayout gridLayout = new GridLayout();

    setLayout(gridLayout);//www.  j  a  v a 2s. c o  m

    System.out.println(gridLayout.getRows());
}

From source file:Main.java

public Main() {

    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"));

    GridLayout gridLayout = new GridLayout();

    setLayout(gridLayout);//from   ww w  .j  av a2  s  .  c  o  m

    System.out.println(gridLayout.getHgap());
}