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 Main() {
    setLayout(new BorderLayout());

    String[] items1 = { "Red", "Blue", "Green" };
    JComboBox<String> comboBox1 = new JComboBox<String>(items1);
    DefaultCellEditor dce1 = new DefaultCellEditor(comboBox1);
    editors.add(dce1);//from w  ww.  j a  va  2s.  com

    String[] items2 = { "Circle", "Square", "Triangle" };
    JComboBox<String> comboBox2 = new JComboBox<String>(items2);
    DefaultCellEditor dce2 = new DefaultCellEditor(comboBox2);
    editors.add(dce2);

    String[] items3 = { "Apple", "Orange", "Banana" };
    JComboBox<String> comboBox3 = new JComboBox<String>(items3);
    DefaultCellEditor dce3 = new DefaultCellEditor(comboBox3);
    editors.add(dce3);

    Object[][] data = { { "Color", "Red" }, { "Shape", "Square" }, { "Fruit", "Banana" }, { "Plain", "Text" } };
    String[] columnNames = { "Type", "Value" };
    DefaultTableModel model = new DefaultTableModel(data, columnNames);
    JTable table = new JTable(model) {
        public TableCellEditor getCellEditor(int row, int column) {
            int modelColumn = convertColumnIndexToModel(column);

            if (modelColumn == 1 && row < 3)
                return editors.get(row);
            else
                return super.getCellEditor(row, column);
        }
    };

    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
}

From source file:Main.java

public TestPane() {
    setLayout(new BorderLayout());
    setBorder(new EmptyBorder(10, 10, 10, 10));
    JTextPane pane = new JTextPane();
    JPanel panel = new JPanel(new BorderLayout());
    JPanel innerPanel = new JPanel(new BorderLayout());

    pane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    innerPanel.add(pane);//w  ww . ja  v a2  s . co m
    panel.add(innerPanel);
    add(panel);
}

From source file:Main.java

public void createUI() {
    JPanel borderPanel = new JPanel(new BorderLayout());

    JLabel northLabel = new JLabel("Nawth");
    borderPanel.add(northLabel, BorderLayout.NORTH);

    JComboBox southCombo = new JComboBox();
    borderPanel.add(southCombo, BorderLayout.SOUTH);

    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.PAGE_AXIS));

    JComboBox firstCombo = new JComboBox();
    centerPanel.add(firstCombo);//from   w  ww.  j a  v  a  2s. c  o m
    centerPanel.add(Box.createVerticalGlue());
    JPanel centerPanelConstrain = new JPanel(new GridBagLayout());
    centerPanelConstrain.add(centerPanel);
    borderPanel.add(centerPanelConstrain, BorderLayout.CENTER);

    getContentPane().add(borderPanel);
    pack();
}

From source file:MainClass.java

public MainClass(File dir) {
    setLayout(new BorderLayout());
    JTree tree = new JTree(addNodes(null, dir));

    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
            System.out.println("You selected " + node);
        }//from w ww .j a  v a 2  s.c o m
    });

    JScrollPane scrollpane = new JScrollPane();
    scrollpane.getViewport().add(tree);
    add(BorderLayout.CENTER, scrollpane);
}

From source file:SplitSample.java

public SplitSample() {
    super("Simple Split Pane");
    setSize(400, 400);//from  ww  w  . j av a2  s .  c  o  m
    getContentPane().setLayout(new BorderLayout());

    JSplitPane spLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JPanel(), new JPanel());
    spLeft.setDividerSize(8);
    spLeft.setContinuousLayout(true);

    JSplitPane spRight = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JPanel(), new JPanel());
    spRight.setDividerSize(8);
    spRight.setContinuousLayout(true);

    split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, spLeft, spRight);
    split.setContinuousLayout(false);
    split.setOneTouchExpandable(true);

    getContentPane().add(split, 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() {
    setLayout(new BorderLayout());
    setSize(300, 300);// ww w  . ja  v a  2 s . c  o  m
    setVisible(true);
    JPanel p = new JPanel(new FlowLayout());

    p.add(b);
    p.add(b1);
    add(p, BorderLayout.SOUTH);
    b.addActionListener(this);
    b1.addActionListener(this);
    m = new ImageIcon[2];
    m[0] = new ImageIcon("m.jpg");
    m[1] = new ImageIcon("m1.jpg");
    l = new JLabel();
    l.setBounds(400, 0, getWidth(), getHeight());
    add(l, BorderLayout.CENTER);
    l.setIcon(m[0]);
}

From source file:Main.java

public Main() {
    setSize(350, 100);/* w  ww .j  av  a 2 s .com*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    bar.addAdjustmentListener(this);
    JPanel pane = new JPanel();
    pane.setLayout(new BorderLayout());
    pane.add(bar, "South");
    setContentPane(pane);
}

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   ww w . ja  va  2  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:Main.java

public Main() {
    super(new BorderLayout());
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);//from www .j  av a  2s  . co  m

    model = new DefaultTreeModel(top);
    tree = new JTree(model);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    JScrollPane treeView = new JScrollPane(tree);
    add(treeView);

    btnAdd.addActionListener(e -> {
        TreePath treePath = tree.getSelectionPath();
        if (treePath != null) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
            DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child " + (++childCount));
            model.insertNodeInto(child, node, node.getChildCount());
        }
    });
    add(btnAdd, BorderLayout.SOUTH);
}

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  .ja  v  a  2 s . c o  m*/

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

    add(pane, BorderLayout.NORTH);
}