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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.PAGE_END);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);//from   w w  w . ja  v a2 s.  c o  m
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.LINE_END);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);// w w w .j a v a 2  s .  c  om
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Property Split");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setResizeWeight(1.0);//  ww  w . ja v a 2  s .c o m
    splitPane.setTopComponent(new JLabel("www.java2s.com"));

    splitPane.setBottomComponent(new JLabel("www.java2s.com"));

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

From source file:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.PAGE_START);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);/*  w  ww  .  ja  v  a 2 s  . c o m*/
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.LINE_START);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);/* w w w.j av a2s.  co m*/
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LINE_ENDS);

    frame.add(outerPanel);//from   w  ww. j av  a  2  s .c om
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:ToggleButtonSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JToggleButton Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    content.add(new JToggleButton("North"), BorderLayout.NORTH);
    content.add(new JToggleButton("East"), BorderLayout.EAST);
    content.add(new JToggleButton("West"), BorderLayout.WEST);
    content.add(new JToggleButton("Center"), BorderLayout.CENTER);
    content.add(new JToggleButton("South"), BorderLayout.SOUTH);
    f.setSize(300, 200);/*from w  ww  .j  a  v a  2  s .  c  o m*/
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);//from w ww .  j  a  va2 s  .  c o  m
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H" };
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList<String> jlist = new JList<>(labels);
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    f.add(scrollPane1, BorderLayout.CENTER);

    MouseListener mouseListener = new MouseAdapter() {
        public void mouseClicked(MouseEvent mouseEvent) {
            JList<String> theList = (JList) mouseEvent.getSource();
            if (mouseEvent.getClickCount() == 2) {
                int index = theList.locationToIndex(mouseEvent.getPoint());
                if (index >= 0) {
                    Object o = theList.getModel().getElementAt(index);
                    System.out.println("Double-clicked on: " + o.toString());
                }/*from   ww w  .ja v  a 2 s  .c  o m*/
            }
        }
    };
    jlist.addMouseListener(mouseListener);
    f.setSize(350, 200);
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Offset Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    final JTextField textField = new JTextField();
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    JButton button = new JButton("Get Offset");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Offset: " + textField.getScrollOffset());
            System.out.println("Visibility: " + textField.getHorizontalVisibility());
            BoundedRangeModel model = textField.getHorizontalVisibility();
            int extent = model.getExtent();
            textField.setScrollOffset(extent);
        }/*from  w  w  w.ja v a2s .  c o m*/
    };
    button.addActionListener(actionListener);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);

}