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[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JDesktopPane desktop = new JDesktopPane();
    JInternalFrame iFrame = new JInternalFrame("Can Do All", true, true, true, true);

    JInternalFrame internalFrames[] = { iFrame, new JInternalFrame("Not Resizable", false, true, true, true),
            new JInternalFrame("Not Closable", true, false, true, true),
            new JInternalFrame("Not Maximizable", true, true, false, true),
            new JInternalFrame("Not Iconifiable", true, true, true, false) };

    int pos = 0;//from  ww w  .ja  v a  2s.  c  o m
    for (JInternalFrame internalFrame : internalFrames) {
        desktop.add(internalFrame);

        internalFrame.setBounds(pos * 25, pos * 25, 200, 100);
        pos++;

        JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER);
        internalFrame.add(label, BorderLayout.CENTER);

        internalFrame.setVisible(true);
    }
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);

    desktop.remove(iFrame);

    frame.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
}

From source file:TabLocation.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();

    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    int mnemonic[] = { KeyEvent.VK_G, KeyEvent.VK_S, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_P,
            KeyEvent.VK_A };/*from w w  w  . ja v  a 2s  .  co m*/
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i], mnemonic[i]);
    }

    tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel buttonConstrsint = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton getQuotesButton = new JButton("Load");
    buttonConstrsint.add(getQuotesButton);
    gui.add(buttonConstrsint, BorderLayout.NORTH);

    getQuotesButton.addActionListener(e -> {
        String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

        Object[][] data = { { "A", "B", "Snowboarding", new Integer(5), new Boolean(false) },
                { "C", "D", "Pool", new Integer(10), new Boolean(false) } };

        JTable table = new JTable(data, columnNames);

        JScrollPane scrollPane = new JScrollPane(table);
        table.setFillsViewportHeight(true);

        gui.add(scrollPane, BorderLayout.CENTER);
        gui.revalidate();//from   w ww.j av  a  2s .  com
        gui.repaint();
    });

    JOptionPane jOptionPane = new JOptionPane(gui);

    JDialog dialog = jOptionPane.createDialog(new JFrame(), "title");
    dialog.setSize(200, 200);
    dialog.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } };
    final String headers[] = { "English", "Digit" };

    TableModel fixedColumnModel = new AbstractTableModel() {
        public int getColumnCount() {
            return 2;
        }/*from www.  j  a  v  a2 s  .c o  m*/

        public String getColumnName(int column) {
            return headers[column];
        }

        public int getRowCount() {
            return 3;
        }

        public Object getValueAt(int row, int column) {
            return rows[row][column];
        }
    };

    JFrame frame = new JFrame("Scrollless Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(fixedColumnModel);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

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

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Verifier Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextField textField1 = new JTextField();
    JTextField textField2 = new JTextField();
    JTextField textField3 = new JTextField();

    InputVerifier verifier = new InputVerifier() {
        public boolean verify(JComponent comp) {
            boolean returnValue;
            JTextField textField = (JTextField) comp;
            try {
                Integer.parseInt(textField.getText());
                returnValue = true;/*w  w  w.  ja  v  a  2  s.  c  om*/
            } catch (NumberFormatException e) {
                returnValue = false;
            }
            return returnValue;
        }
    };

    textField1.setInputVerifier(verifier);
    textField3.setInputVerifier(verifier);

    frame.add(textField1, BorderLayout.NORTH);
    frame.add(textField2, BorderLayout.CENTER);
    frame.add(textField3, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    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" };

    JFrame frame = new JFrame("Tooltip Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTable table = new JTable(rows, headers);

    JLabel headerRenderer = new DefaultTableCellRenderer();
    String columnName = table.getModel().getColumnName(0);
    headerRenderer.setText(columnName);//from  w  ww  .  ja  va 2  s  . co m
    headerRenderer.setToolTipText("Wave");

    TableColumnModel columnModel = table.getColumnModel();
    TableColumn column = columnModel.getColumn(0);
    column.setHeaderRenderer((TableCellRenderer) headerRenderer);

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

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setUndecorated(true);/*from  www.  j  a  v a2s .com*/
    frame.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            point.x = e.getX();
            point.y = e.getY();
        }
    });
    frame.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            Point p = frame.getLocation();
            frame.setLocation(p.x + e.getX() - point.x, p.y + e.getY() - point.y);
        }
    });

    frame.setSize(300, 300);
    frame.setLocation(200, 200);
    frame.setLayout(new BorderLayout());

    frame.getContentPane().add(new JLabel("Drag to move", JLabel.CENTER), BorderLayout.CENTER);

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    menuBar.add(menu);
    JMenuItem item = new JMenuItem("Exit");
    item.addActionListener(e -> System.exit(0));
    menu.add(item);
    frame.setJMenuBar(menuBar);
    frame.setVisible(true);
}

From source file:TreeEdit.java

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

    Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" };
    JTree tree = new JTree(array);
    tree.setEditable(true);/*from ww  w  .jav a 2  s.  c  o  m*/
    tree.setRootVisible(true);

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
    String elements[] = { "A", "B", "C", "D" };
    JComboBox comboBox = new JComboBox(elements);
    comboBox.setEditable(true);
    TreeCellEditor comboEditor = new DefaultCellEditor(comboBox);
    TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor);
    tree.setCellEditor(editor);

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

From source file:TabSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    String titles[] = { "A", "B", "C", "D", "E", "F" };
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i]);/*from  ww w  .  j a  va2s.  c o m*/
    }

    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:Main.java

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

    JDesktopPane desktop = new JDesktopPane();

    JInternalFrame internalFrames[] = { new JInternalFrame("Can Do All", true, true, true, true),
            new JInternalFrame("Not Resizable", false, true, true, true),
            new JInternalFrame("Not Closable", true, false, true, true),
            new JInternalFrame("Not Maximizable", true, true, false, true),
            new JInternalFrame("Not Iconifiable", true, true, true, false) };

    int pos = 0;//from   w  w w . java2s .c om
    for (JInternalFrame internalFrame : internalFrames) {
        desktop.add(internalFrame);

        internalFrame.setBounds(pos * 25, pos * 25, 200, 100);
        pos++;

        JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER);
        internalFrame.add(label, BorderLayout.CENTER);

        internalFrame.setVisible(true);
    }
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);

    AccessibleContext context = desktop.getAccessibleContext();

    frame.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
}