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:Main.java

public Main() {
    setLayout(new BorderLayout());

    list = new JList(label);
    JScrollPane pane = new JScrollPane(list);

    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m.setLeadAnchorNotificationEnabled(false);
    list.setSelectionModel(m);/*from   w w  w.j  a va 2 s.c  o  m*/

    m.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            System.out.println(e.toString());
        }
    });

    add(pane, BorderLayout.NORTH);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());

    list = new JList(label);
    JScrollPane pane = new JScrollPane(list);

    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m.setLeadAnchorNotificationEnabled(false);
    list.setSelectionModel(m);//from  w  ww.  ja v a2 s . c  o  m

    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            System.out.println(e.toString());
        }
    });

    add(pane, BorderLayout.NORTH);
}

From source file:MainClass.java

public MainClass() {
    setLayout(new BorderLayout());

    list = new JList(label);
    JScrollPane pane = new JScrollPane(list);

    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m.setLeadAnchorNotificationEnabled(false);
    list.setSelectionModel(m);/*from   w  ww. j  a  v a2s. c  o m*/

    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            System.out.println(e.toString());
        }
    });

    add(pane, BorderLayout.NORTH);
}

From source file:Main.java

public Main() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);//from   www.j  a  va2s  . c  om
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    JScrollPane scroller = new JScrollPane(textArea);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(scroller, BorderLayout.CENTER);

    textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
            updateButtons();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:Main.java

public Main() {
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(new JButton("Foo"));
    buttonPanel.add(Box.createHorizontalStrut(10));
    buttonPanel.add(new JButton("Bar"));

    String[] columnNames = { "Mon", "Tues", "Wed" };
    DefaultTableModel model = new DefaultTableModel(columnNames, 25);
    JTable table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.getViewport().setPreferredSize(table.getPreferredSize());

    JLabel southLabel = new JLabel("OK!");
    southLabel.setForeground(Color.white);
    JPanel southPanel = new JPanel();
    southPanel.add(southLabel);/* w  w  w  .  ja  va2s.c  om*/

    setLayout(new BorderLayout(5, 5));
    add(buttonPanel, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(southPanel, BorderLayout.SOUTH);
}

From source file:UndoRedoTextArea.java

public UndoRedoTextArea() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);/*from  w w  w . ja  v  a 2s  .  co  m*/
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    JScrollPane scroller = new JScrollPane(textArea);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(scroller, BorderLayout.CENTER);

    textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
            updateButtons();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:MainClass.java

public MainClass() throws Exception {
    getContentPane().setLayout(new BorderLayout());

    Object[][] data = { { "A", "B", "C", new Integer(5), new Boolean(false) },
            { "D", "E", "F", new Integer(3), new Boolean(true) } };

    String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

    table = new JTable(data, columnNames);

    JPanel tPanel = new JPanel(new BorderLayout());
    tPanel.add(table.getTableHeader(), BorderLayout.NORTH);
    tPanel.add(table, BorderLayout.CENTER);

    getContentPane().add(tPanel, BorderLayout.CENTER);

    Document document = new Document();
    PdfWriter writer;//from w  w  w.  jav  a  2 s  .  c  om

    writer = PdfWriter.getInstance(document, new FileOutputStream("my_jtable_shapes.pdf"));

    // writer = PdfWriter.getInstance(document, new
    // FileOutputStream("my_jtable_fonts.pdf"));

    document.open();
    PdfContentByte cb = writer.getDirectContent();

    PdfTemplate tp = cb.createTemplate(500, 500);
    Graphics2D g2;

    g2 = tp.createGraphicsShapes(500, 500);

    // g2 = tp.createGraphics(500, 500);
    table.print(g2);
    g2.dispose();
    cb.addTemplate(tp, 30, 300);

    // step 5: we close the document
    document.close();
}

From source file:StocksTable4.java

public StocksTable4() {
    super("Stocks Table");
    setSize(600, 300);//from  w  w  w.jav  a2  s.c om

    m_data = new StockTableData();

    m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT);
    m_title.setFont(new Font("TimesRoman", Font.BOLD, 24));
    m_title.setForeground(Color.black);
    getContentPane().add(m_title, BorderLayout.NORTH);

    m_table = new JTable();
    m_table.setAutoCreateColumnsFromModel(false);
    m_table.setModel(m_data);

    for (int k = 0; k < StockTableData.m_columns.length; k++) {
        DefaultTableCellRenderer renderer = new ColoredTableCellRenderer();
        renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment);
        TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null);
        m_table.addColumn(column);
    }

    JTableHeader header = m_table.getTableHeader();
    header.setUpdateTableInRealTime(true);
    header.addMouseListener(m_data.new ColumnListener(m_table));
    header.setReorderingAllowed(true);

    JScrollPane ps = new JScrollPane();
    ps.getViewport().add(m_table);
    getContentPane().add(ps, BorderLayout.CENTER);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:Main.java

public Main() {
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new GridLayout(3, 1, 0, 5));
    northPanel.add(label);/*from  www  .java2 s .c  om*/
    northPanel.add(button);
    northPanel.add(comboBox);
    add(northPanel, BorderLayout.NORTH);
    JPanel southPanel = new JPanel();

    ItemHandler handler = new ItemHandler();
    southPanel.setLayout(new GridLayout(1, radio.length));

    ButtonGroup group = new ButtonGroup();
    for (int i = 0; i < radio.length; i++) {
        radio[i] = new JRadioButton(strings[i]);
        radio[i].addItemListener(handler);
        group.add(radio[i]);
        southPanel.add(radio[i]);
    }

    add(southPanel, BorderLayout.SOUTH);

    setSize(300, 200);
    setVisible(true);
    radio[0].setSelected(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public TabPanel() {
    JPanel innerPanel = new JPanel();
    innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS));
    int USER_INPUT = 10;
    for (int i = 0; i < USER_INPUT; i++) {
        JPanel p = new JPanel(new BorderLayout());
        JLabel label = new JLabel("Label" + i);
        JTextField textArea = new JTextField();
        p.add(label, BorderLayout.NORTH);
        p.add(textArea, BorderLayout.CENTER);
        innerPanel.add(p);/*  ww w.ja  v  a  2 s . c  om*/
    }

    JScrollPane scrollPane = new JScrollPane(innerPanel);
    scrollPane.setPreferredSize(new Dimension(400, 200));
    this.add(scrollPane);
}