Example usage for java.awt BorderLayout CENTER

List of usage examples for java.awt BorderLayout CENTER

Introduction

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

Prototype

String CENTER

To view the source code for java.awt BorderLayout CENTER.

Click Source Link

Document

The center layout constraint (middle of container).

Usage

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);/*from w w  w  . ja  va2  s  .  c  o  m*/
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 5; j++) {
            model.addElement(labels[j]);
        }
    }
    System.out.println(model.indexOf("A", 0));

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

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

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);/* w  w  w .j ava 2 s . c om*/
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 5; j++) {
            model.addElement(labels[j]);
        }
    }
    System.out.println(model.getElementAt(1));

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

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

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);// www. ja  va  2s .  c o m
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 5; j++) {
            model.addElement(labels[j]);
        }
    }
    System.out.println(model.lastIndexOf("A"));

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

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

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);/*from  ww  w.  java  2  s  . c o  m*/
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 5; j++) {
            model.addElement(labels[j]);
        }
    }
    System.out.println(model.lastIndexOf("A", 0));

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

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

From source file:Main.java

public static void main(String[] a) {
    final JTextField textField = new JTextField(5);

    textField.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
        }/*from  w ww .j a v a  2s .c  o  m*/

        public void focusLost(FocusEvent e) {
            if (!e.isTemporary()) {
                String content = textField.getText();
                if (!content.equals("a")) {
                    System.out.println("illegal value! " + content);
                    SwingUtilities.invokeLater(new FocusGrabber(textField));
                }
            }
        }
    });
    JFrame frame = new JFrame();
    frame.add(textField, BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.setVisible(true);

}

From source file:MainClass.java

public static void main(String args[]) {
    String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    String headers[] = { "Upper", "Lower" };

    JComboBox comboBox = new JComboBox(rows[0]);
    comboBox.setMaximumRowCount(4);//from  w  w  w  . j  av  a 2  s. c  o m

    TableCellEditor editor = new DefaultCellEditor(comboBox);

    JFrame frame = new JFrame("JTable Anatomy");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(new DefaultTableModel(rows, headers));

    table.getColumnModel().getColumn(1).setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:TableModelListenerDemo.java

public static void main(String args[]) {

    final Object rowData[][] = { { "1", "one", "I" }, { "2", "two", "II" }, { "3", "three", "III" } };
    final String columnNames[] = { "#", "English", "Roman" };

    final JTable table = new JTable(rowData, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);
    table.getModel().addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            System.out.println(e);
        }//from w  ww. jav a  2  s  .  c om
    });

    table.setValueAt("", 0, 0);
    JFrame frame = new JFrame("Resizing Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);// ww  w .ja  va  2s  .  c o m
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 5; j++) {
            model.addElement(labels[j]);
        }
    }
    Object[] objs = new Object[10];

    System.out.println(model.elementAt(1));

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

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

From source file:MainClass.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    final DefaultComboBoxModel model = new DefaultComboBoxModel(labels);

    JFrame frame = new JFrame("Shared Data");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox comboBox1 = new JComboBox(model);
    comboBox1.setMaximumRowCount(5);/*from w w w . ja v a2  s .  com*/
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList jlist = new JList(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
        }
    };
    button.addActionListener(actionListener);

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

From source file:Main.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>(labels);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//from  ww w . java2  s. c  o m
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
        }
    };
    button.addActionListener(actionListener);

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