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() {
    super(new BorderLayout());
    String[] data = { "Math", "Computer", "Physics", "Chemistry" };
    list = new JList(data);
    list.addListSelectionListener(new SelectionHandler());
    JScrollPane jsp = new JScrollPane(list);
    this.add(jsp, BorderLayout.CENTER);
}

From source file:Main.java

/**
 * Initialises the {@link JDialog} for the {@link JComponent}.
 * //from   www . j  a v  a2 s.  c o m
 * @param dialog
 * @param component
 * @param parentComponent
 */
private static void initDialog(final JDialog dialog, final JComponent component,
        final Component parentComponent) {
    dialog.setResizable(true);
    dialog.setComponentOrientation(component.getComponentOrientation());
    Container contentPane = dialog.getContentPane();

    contentPane.setLayout(new BorderLayout());
    contentPane.add(component, BorderLayout.CENTER);

    final int buttonWidth = 75;

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4));

    buttonPanel.add(Box.createHorizontalGlue());

    @SuppressWarnings("serial")
    final Action closeAction = new AbstractAction("Close") {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };

    final JButton button = new JButton(closeAction);
    fixWidth(button, buttonWidth);
    buttonPanel.add(button);

    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.setUndecorated(true);
            component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parentComponent);
    WindowAdapter adapter = new WindowAdapter() {
        //         private boolean gotFocus = false;
        public void windowClosing(WindowEvent we) {
            fireAction(we.getSource(), closeAction, "close");
        }
    };
    dialog.addWindowListener(adapter);
    dialog.addWindowFocusListener(adapter);
}

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

    m.clearSelection();

    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 w  w  . j  av  a  2 s.co m

    m.addSelectionInterval(1, 1);

    add(pane, BorderLayout.NORTH);
}

From source file:Main.java

public Main() {
    super(new BorderLayout());
    JScrollPane jsp = new JScrollPane(tree);
    add(jsp, BorderLayout.CENTER);
}

From source file:MainClass.java

public MainClass() {
    super(true);//w  ww  .  ja v a 2  s . c  o  m

    setLayout(new BorderLayout());

    JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300);
    JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);

    hbar.setUnitIncrement(2);
    hbar.setBlockIncrement(1);

    hbar.addAdjustmentListener(new MyAdjustmentListener());
    vbar.addAdjustmentListener(new MyAdjustmentListener());

    add(hbar, BorderLayout.SOUTH);
    add(vbar, BorderLayout.EAST);
    add(label, BorderLayout.CENTER);
}

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  .j ava2 s  . c  o  m*/

    try {
        DefaultListSelectionModel mClone = (DefaultListSelectionModel) m.clone();
    } catch (CloneNotSupportedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    add(pane, BorderLayout.NORTH);
}

From source file:Main.java

public Main() throws Exception {
    setSize(400, 240);//from  w ww. ja  v a 2s .c o m
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    getContentPane().add(topPanel, BorderLayout.CENTER);

    RTFEditorKit rtf = new RTFEditorKit();
    JEditorPane editor = new JEditorPane();
    editor.setEditorKit(rtf);

    JScrollPane scroller = new JScrollPane();
    scroller.getViewport().add(editor);
    topPanel.add(scroller, BorderLayout.CENTER);

    FileInputStream fi = new FileInputStream("test.rtf");
    rtf.read(fi, editor.getDocument(), 0);
}

From source file:Main.java

public Main() {
    JPanel borderLayoutPanel = new JPanel(new BorderLayout());
    borderLayoutPanel.setBorder(BorderFactory.createTitledBorder("BorderLayout Panel"));
    borderLayoutPanel.add(createGridPanel(), BorderLayout.CENTER);

    JPanel flowLayoutPanel = new JPanel(new FlowLayout());
    flowLayoutPanel.setBorder(BorderFactory.createTitledBorder("FlowLayout Panel"));
    flowLayoutPanel.add(createGridPanel());

    setBorder(BorderFactory.createEmptyBorder(GAP, GAP, GAP, GAP));
    setLayout(new GridLayout(1, 0, GAP, 0));
    add(borderLayoutPanel);//w  ww. j a  v a  2s  .c  o m
    add(flowLayoutPanel);
}

From source file:Main.java

Main() {
    setSize(500, 300);//from   ww  w. ja  va  2 s .  c om
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());
    JScrollPane pane = new JScrollPane();
    txtMain = new JTextArea();
    pane.setViewportView(txtMain);
    this.add(pane, BorderLayout.CENTER);

    JButton btnAddText = new JButton("Add Text");
    btnAddText.addActionListener(e -> {
        txtMain.setText(txtMain.getText()
                + "\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi sagittis id nibh vel rhoncus. ");
        String text = txtMain.getText();
        txtMain.setCaretPosition(text != null ? text.length() : 0);
    });
    add(btnAddText, BorderLayout.SOUTH);
    setVisible(true);
}