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 f = new JFrame("This is BOX LAYOUT");
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
    panel1.setBackground(Color.yellow);

    JPanel panel2 = new JPanel();
    panel2.setLayout(new FlowLayout());
    panel2.setBackground(Color.ORANGE);

    for (int i = 0; i < 5; i++)
        panel1.add(new JCheckBox("CheckBox " + (i + 1)));

    f.add(panel1, BorderLayout.WEST);
    f.add(panel2, BorderLayout.CENTER);
    f.setVisible(true);/*from   w ww.j  av a2 s. c  o  m*/
    f.setSize(300, 300);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    JTextPane textPane = new JTextPane();

    JButton button = new JButton("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    panel.setLayout(new BorderLayout());
    panel.setPreferredSize(new Dimension(200, 200));

    panel.add(textPane, BorderLayout.CENTER);
    panel.add(button, BorderLayout.SOUTH);
    textPane.addStyle("myStyle", null);

    button.addActionListener(e -> {/*  w w w .ja va 2 s  . c om*/
        StyledDocument doc = textPane.getStyledDocument();
        int start = textPane.getSelectionStart();
        int end = textPane.getSelectionEnd();
        if (start == end) {
            return;
        }
        if (start > end) {
            int life = start;
            start = end;
            end = life;
        }
        Style style = textPane.getStyle("myStyle");

        if (StyleConstants.isBold(style)) {
            StyleConstants.setBold(style, false);
        } else {
            StyleConstants.setBold(style, true);
        }
        doc.setCharacterAttributes(start, end - start, style, false);
    });

    frame.add(panel);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    JOptionPane pane = new JOptionPane("Some message", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION) {
        @Override/* w w w  .java  2 s .c om*/
        public void setValue(Object newValue) {
            super.setValue(newValue);
            JOptionPane.showMessageDialog(frame.getContentPane(), "You have hit " + newValue);
        }
    };
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JLabel("Some panel in the middle"), BorderLayout.CENTER);
    frame.add(pane, BorderLayout.SOUTH);
    frame.pack();
    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);

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic('p');
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);//www .  ja va  2 s.  co m
    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);

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    System.out.println(userLabel.getDisplayedMnemonicIndex());

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic('p');
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);/*from  w w  w  .  j  a  v a  2 s .  c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jtp.setPreferredSize(new Dimension(400, 200));
    createTab("Reds", Color.RED);
    f.add(jtp, BorderLayout.CENTER);
    f.pack();/* w ww. j  a  v  a 2  s.co  m*/
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    System.out.println(userLabel.getDisplayedMnemonic());

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic('p');
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);// ww  w. j a  v a2  s .com
    frame.setVisible(true);
}

From source file:Main.java

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

    MyModel myArrayClass = new MyModel(25);

    MyView panel = new MyView(myArrayClass);
    myArrayClass.myView = panel;//from  w  ww  .j ava  2  s. c  om

    JButton sortButton = new JButton("Sort");
    sortButton.addActionListener(e -> performSorting(myArrayClass));
    f.getContentPane().add(sortButton, BorderLayout.NORTH);
    f.getContentPane().add(panel, BorderLayout.CENTER);
    f.setSize(400, 400);
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    System.out.println(userLabel.getHorizontalAlignment());

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic('p');
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);//ww  w. j  a  v  a 2  s . c o m
    frame.setVisible(true);
}

From source file:DualSample.java

public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };

    JFrame f = new JFrame("Sample Components");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList list = new JList(labels);
    JScrollPane scrollPane = new JScrollPane(list);

    JComboBox comboBox = new JComboBox(labels);
    comboBox.setMaximumRowCount(4);//  www  .ja  v  a2s.  co  m

    Container contentPane = f.getContentPane();
    contentPane.add(comboBox, BorderLayout.NORTH);
    contentPane.add(scrollPane, BorderLayout.CENTER);

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