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

    Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
            { "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
    Object columnNames[] = { "1", "2", "3" };
    JTable table = new JTable(rowData, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);

    table.setTableHeader(null);//ww  w  .j  a  v a 2 s.  c o m

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:JSplitPaneVerticalSetTopBottom.java

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

    JComponent topButton = new JButton("Left");
    JComponent bottomButton = new JButton("Right");
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(topButton);
    splitPane.setBottomComponent(bottomButton);

    horizontalFrame.add(splitPane, BorderLayout.CENTER);
    horizontalFrame.setSize(150, 150);/*  www .j  a v a 2 s.  c  om*/
    horizontalFrame.setVisible(true);

}

From source file:Main.java

public static void main(String arg[]) {
    JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());

    JPanel gb = new JPanel(new GridBagLayout());
    JLabel content = new JLabel("Some text");

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.weighty = 1;/* w w  w . j a v  a 2s . c  o m*/

    gb.add(content, gbc); // gbc is containing the GridBagConstraints
    frame.add(gb, BorderLayout.CENTER);

    frame.setVisible(true);
}

From source file:SpinnerDateSample.java

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

    SpinnerModel model1 = new SpinnerDateModel();
    JSpinner spinner1 = new JSpinner(model1);

    JLabel label1 = new JLabel("Dates/Date");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.CENTER);

    frame.setSize(200, 90);/*from w  w w  . j a  v a2  s .  c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    //Read from an input stream
    InputStream is = new BufferedInputStream(new FileInputStream("source.gif"));
    Image image = ImageIO.read(is);

    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();/*from   w w  w . ja v  a 2  s . c  om*/
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    Object rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    Object headers[] = { "Upper", "Lower" };
    JTable table = new JTable(rows, headers);
    table.setTableHeader(null);//  w  w w. ja va2  s  .c  o m
    JScrollPane scrollPane = new JScrollPane(table);
    JFrame frame = new JFrame();
    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) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

    desktop.add(internalFrame);//from w  ww.j  a va 2s.  c  o m

    internalFrame.setBounds(25, 25, 200, 100);

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

    internalFrame.setVisible(true);

    desktop.getDesktopManager().maximizeFrame(internalFrame);

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

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("JSpinner Dates");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpinnerModel model1 = new SpinnerDateModel();
    JSpinner spinner1 = new JSpinner(model1);
    JLabel label1 = new JLabel("All");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.NORTH);

    frame.setSize(200, 90);//from  w ww. j a  v a  2  s . c om
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);/* w  ww .  jav a 2s  .co  m*/

    JDialog dialog = new JDialog(frame, "Dialog", true);

    JPanel mainGui = new JPanel(new BorderLayout());
    mainGui.setBorder(new EmptyBorder(20, 20, 20, 20));
    mainGui.add(new JLabel("Contents go here"), BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel(new FlowLayout());
    mainGui.add(buttonPanel, BorderLayout.SOUTH);

    JButton close = new JButton("Close");
    close.addActionListener(e -> dialog.setVisible(false));

    buttonPanel.add(close);

    frame.setVisible(true);

    dialog.setContentPane(mainGui);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:Main.java

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

    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);

    JTextField textField = new JTextField();
    label.setLabelFor(textField);/*from   w w w. j ava 2s. c o  m*/

    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}