Example usage for java.awt BorderLayout NORTH

List of usage examples for java.awt BorderLayout NORTH

Introduction

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

Prototype

String NORTH

To view the source code for java.awt BorderLayout NORTH.

Click Source Link

Document

The north layout constraint (top of container).

Usage

From source file:FileChooserTest.java

public FileChooserTest() {
    JPanel p = new JPanel();
    open.addActionListener(new OpenL());
    p.add(open);//w ww .jav  a  2  s  .com
    save.addActionListener(new SaveL());
    p.add(save);
    Container cp = getContentPane();
    cp.add(p, BorderLayout.SOUTH);
    dir.setEditable(false);
    filename.setEditable(false);
    p = new JPanel();
    p.setLayout(new GridLayout(2, 1));
    p.add(filename);
    p.add(dir);
    cp.add(p, BorderLayout.NORTH);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    JPanel upper = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    upper.setLayout(gridbag);//ww  w.ja v a 2  s.co  m
    GridBagConstraints gbc = new GridBagConstraints();

    JButton toolbar1 = new JButton("toolbar1");
    JButton toolbar2 = new JButton("toolbar2");
    JButton toolbar3 = new JButton("toolbar3");

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.WEST;
    upper.add(toolbar1, gbc);

    gbc.gridx = 1;
    gbc.anchor = GridBagConstraints.CENTER;
    upper.add(toolbar2, gbc);

    gbc.gridx = 2;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    upper.add(toolbar3, gbc);

    add(upper, BorderLayout.NORTH);

    JPanel something = new JPanel();
    something.setBackground(Color.WHITE);
    something.setPreferredSize(new Dimension(600, 600));
    something.repaint();
    add(something, BorderLayout.CENTER);

    pack();
    setVisible(true);
}

From source file:Main.java

public Main() {
    try {/*from  www . j  a v  a2  s  .com*/
        robot = new Robot();
    } catch (Exception e1) {
        e1.printStackTrace();
    }

    timer = new Timer(3000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
            Image image = robot.createScreenCapture(size);
            label.setIcon(new ImageIcon(image));
            frame.setVisible(true);
        }
    });
    timer.setRepeats(false);

    button.addActionListener(e -> {
        frame.setVisible(false);
        timer.start();
    });

    frame.add(button, BorderLayout.NORTH);
    frame.add(label, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1024, 768);
    frame.setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    setLayout(new BorderLayout());
    model = new DefaultListModel();
    list = new JList(model);
    JScrollPane pane = new JScrollPane(list);
    JButton addButton = new JButton("Add Element");
    JButton removeButton = new JButton("Remove Element");
    for (int i = 0; i < 15; i++)
        model.addElement("Element " + i);

    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            model.addElement("Element " + counter);
            counter++;//from ww  w.  j a  v a  2s .c  o  m
        }
    });
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (model.getSize() > 0)
                model.removeElementAt(0);
        }
    });

    add(pane, BorderLayout.NORTH);
    add(addButton, BorderLayout.WEST);
    add(removeButton, BorderLayout.EAST);
}

From source file:CardFrame.java

public CardFrame(String title) {
    setLayout(new BorderLayout(10, 10));
    nextCard.addActionListener(this);
    prevCard.addActionListener(this);
    firstCard.addActionListener(this);
    lastCard.addActionListener(this);

    Panel buttonsPanel = new Panel(new FlowLayout(FlowLayout.CENTER));
    buttonsPanel.add(firstCard);/*from ww w .jav  a  2  s  .com*/
    buttonsPanel.add(prevCard);
    buttonsPanel.add(nextCard);
    buttonsPanel.add(lastCard);

    setCardLayout();
    add(BorderLayout.CENTER, cardPanel);
    add(BorderLayout.NORTH, buttonsPanel);
}

From source file:ToolBarwithCheckBox.java

public ToolbarPanel() {
    setLayout(new BorderLayout());
    JToolBar toolbar = new JToolBar();
    for (int i = 1; i < 4; i++) {
        JCheckBox cbox = new JCheckBox("Checkbox #" + i);
        toolbar.add(cbox);//from  www.j  a  v a2 s. c  o  m
        cbox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JCheckBox source = (JCheckBox) (e.getSource());
                System.out.println("Toolbar " + source.getText());
            }
        });
    }

    add(toolbar, BorderLayout.NORTH);
}

From source file:ToolbarFrame2.java

public ToolbarFrame2() {
    setSize(450, 250);//from www  .jav a2s .  com

    ActionListener printListener = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println(ae.getActionCommand());
        }
    };

    // JPanel works similarly to Panel, so we'll use it
    JPanel toolbar = new JPanel();
    toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));

    cutButton = new JButton("Cut");
    cutButton.addActionListener(printListener);
    toolbar.add(cutButton);

    copyButton = new JButton("Copy");
    copyButton.addActionListener(printListener);
    toolbar.add(copyButton);

    pasteButton = new JButton("Paste");
    pasteButton.addActionListener(printListener);
    toolbar.add(pasteButton);

    add(toolbar, BorderLayout.NORTH); // The new BorderLayout add

    JPanel lnfPanel = new JPanel();
    macButton = new JButton("Mac");
    macButton.addActionListener(printListener);
    lnfPanel.add(macButton);
    javaButton = new JButton("Metal");
    javaButton.addActionListener(printListener);
    lnfPanel.add(javaButton);
    motifButton = new JButton("Motif");
    motifButton.addActionListener(printListener);
    lnfPanel.add(motifButton);
    winButton = new JButton("Windows");
    winButton.addActionListener(printListener);
    lnfPanel.add(winButton);
    add(lnfPanel, BorderLayout.SOUTH);
}

From source file:Main.java

public Main(String title) {
    super(title);
    this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    Container contentPane = this.getContentPane();
    ButtonGroup group = new ButtonGroup();
    small = new JRadioButton("small");
    medium = new JRadioButton("medium");
    large = new JRadioButton("large");

    group.add(small);//  w  w w .j ava 2s . c  o  m
    group.add(medium);
    group.add(large);
    button = new JButton("Click here.");
    button.setBounds(100, 50, 100, 50);
    JPanel center = new JPanel();
    center.setLayout(null);
    center.add(button);
    contentPane.add(center, BorderLayout.CENTER);

    JPanel north = new JPanel();
    north.add(small);
    north.add(medium);
    north.add(large);
    contentPane.add(north, BorderLayout.NORTH);

    ChangeSize listener = new ChangeSize(button);
    small.addItemListener(listener);
    medium.addItemListener(listener);
    large.addItemListener(listener);
}

From source file:Main.java

private JPanel createTabbedPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    JTextField field = new JTextField(50);
    JEditorPane pane = new JEditorPane();
    pane.setPreferredSize(new Dimension(700, 500));

    panel.add(field, BorderLayout.NORTH);
    panel.add(pane, BorderLayout.CENTER);
    return panel;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    panel.setLayout(new BorderLayout());
    setContentPane(panel);//from   ww  w.  j a v  a 2s .  co m
    JTextPane textA = new JTextPane();
    textA.setName("text");
    textA.setContentType("text/html");
    DefaultCaret caret = (DefaultCaret) textA.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    JScrollPane filler = new JScrollPane(textA, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    JTextPane textB = new JTextPane();
    textB.setName("text" + "_T");
    textB.setFont(textA.getFont());
    DefaultCaret caret_T = (DefaultCaret) textB.getCaret();
    caret_T.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    JScrollPane filler_T = new JScrollPane(textB, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    panel.add(filler, BorderLayout.NORTH);
    panel.add(filler_T, BorderLayout.CENTER);
    pack();
}