Example usage for java.awt BorderLayout BorderLayout

List of usage examples for java.awt BorderLayout BorderLayout

Introduction

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

Prototype

public BorderLayout() 

Source Link

Document

Constructs a new border layout with no gaps between components.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.pack();/*from  w  w w .j av a 2 s  . c om*/

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(null);
    for (int i = 0; i < 4; i++) {
        JPanel panel = new JPanel();
        panel.setBounds((i * 75) + 475, 25, 75, 100);
        System.out.println(panel.getBounds());
        contentPane.add(panel);
        panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3));
    }
    System.out.println(getComponentAt(contentPane, new Point(475, 25)));
    System.out.println(getComponentAt(contentPane, new Point(100, 25)));
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel label = new JLabel("java2s.com");

    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(label);//ww w .jav a 2 s. c  o m

    JPanel buttons = new JPanel(new GridLayout(0, 1));
    for (int index = 0; index < 10; index++) {
        buttons.add(new JButton(String.valueOf(index)));
    }

    JPanel right = new JPanel(new BorderLayout());
    right.add(buttons, BorderLayout.NORTH);
    frame.add(right, BorderLayout.EAST);

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

From source file:Main.java

public static void main(String[] args) {
    int nb = 4;//w  w  w  .j  a  va  2  s.  c  o m
    final int frameCount = nb;

    for (int i = 0; i < frameCount; i++) {
        JFrame frame = new JFrame("Frame number " + i);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JPanel p = new JPanel(new BorderLayout());
        p.add(new JLabel("Click on the corner to close..."), BorderLayout.CENTER);
        frame.setContentPane(p);
        frame.setSize(200, 200);
        frame.setLocation(100 + 20 * i, 100 + 20 * i);
        frame.setVisible(true);
    }
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout());
    gui.setPreferredSize(new Dimension(400, 100));

    JDesktopPane dtp = new JDesktopPane();
    gui.add(dtp, BorderLayout.CENTER);

    JButton newFrame = new JButton("Add Frame");

    ActionListener listener = new ActionListener() {
        private int disp = 10;

        @Override/*from  w  w w .ja  v a 2  s  . c  o m*/
        public void actionPerformed(ActionEvent e) {
            JInternalFrame jif = new JInternalFrame();
            dtp.add(jif);
            jif.setLocation(disp, disp);
            jif.setSize(100, 100);
            disp += 10;
            jif.setVisible(true);
        }
    };
    newFrame.addActionListener(listener);

    gui.add(newFrame, BorderLayout.PAGE_START);

    JFrame f = new JFrame();
    f.add(gui);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setLocationByPlatform(true);

    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Label Focus Example");
    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 a v a  2 s  .co  m*/
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.setSize(250, 150);
    frame.setVisible(true);

    textField.setText("Loooooooooooooooooooooooooooooooooooooooooooooooooooooooong");
    BoundedRangeModel model = textField.getHorizontalVisibility();
    int extent = model.getExtent();
    textField.setScrollOffset(extent);
    System.out.println("extent:" + extent);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new TestPane());
    frame.setSize(100, 100);/*from w w w .j  a v  a  2s.  c o  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);

    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  ww  w  .jav  a  2  s  .com
    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.setLayout(new BorderLayout());
    frame.add(new TestPane());
    frame.pack();//  w  w  w . java 2 s. c o  m
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel northPanel = new JPanel(new GridLayout(2, 1));

    JPanel welcomePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    welcomePanel.add(new JLabel("Welcome"));

    northPanel.add(welcomePanel);/*from  w  w  w.j a  v  a 2 s  .  co m*/

    JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

    JRadioButton button1 = new JRadioButton("Button 1", true);
    JRadioButton button2 = new JRadioButton("Button 2", false);

    ButtonGroup group = new ButtonGroup();
    group.add(button1);
    group.add(button2);

    radioPanel.add(button1);
    radioPanel.add(button2);

    northPanel.add(radioPanel);

    JPanel middlePanel = new JPanel(new GridLayout(3, 3));

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            middlePanel.add(new JButton("Button " + i + j));
        }
    }

    JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

    southPanel.add(new JLabel("Whose turn:"));
    southPanel.add(new JButton("Reset"));

    frame.add(northPanel, BorderLayout.NORTH);
    frame.add(middlePanel, BorderLayout.CENTER);
    frame.add(southPanel, 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);

    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);/* w  w  w .  ja va 2  s. c  o  m*/
    frame.setVisible(true);
}