Example usage for java.awt BorderLayout CENTER

List of usage examples for java.awt BorderLayout CENTER

Introduction

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

Prototype

String CENTER

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

Click Source Link

Document

The center layout constraint (middle of container).

Usage

From source file:OffsetSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Offset Example");
    Container content = frame.getContentPane();
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);
    final JTextField textField = new JTextField();
    label.setLabelFor(textField);//from  ww  w . j av  a  2s.c  o  m
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    content.add(panel, BorderLayout.NORTH);
    JButton button = new JButton("Get Offset");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Offset: " + textField.getScrollOffset());
            System.out.println("Visibility: " + textField.getHorizontalVisibility());
            BoundedRangeModel model = textField.getHorizontalVisibility();
            int extent = model.getExtent();
            textField.setScrollOffset(extent);
        }
    };
    button.addActionListener(actionListener);
    content.add(button, BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:TreeArraySample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JTreeSample");

    Vector oneVector = new NamedVector("One", args);
    Vector twoVector = new NamedVector("Two", new String[] { "Mercury", "Venus", "Mars" });
    Vector threeVector = new NamedVector("Three");
    threeVector.add(System.getProperties());
    threeVector.add(twoVector);// w w  w .ja va 2  s  .  co  m
    Object rootNodes[] = { oneVector, twoVector, threeVector };
    Vector rootVector = new NamedVector("Root", rootNodes);
    JTree tree = new JTree(rootVector);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    //    frame.getContentPane().add(tree, BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.setVisible(true);
}

From source file:FileSamplePanel.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JLabel directoryLabel = new JLabel(" ");
    directoryLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 36));
    frame.add(directoryLabel, BorderLayout.NORTH);

    final JLabel filenameLabel = new JLabel(" ");
    filenameLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 36));
    frame.add(filenameLabel, BorderLayout.SOUTH);

    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setControlButtonsAreShown(false);
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();//from  w  ww.  j ava 2  s  .c  om
    frame.setVisible(true);
}

From source file:DefaultMutableTreeNodeAddingDemo.java

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

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode mercury = new DefaultMutableTreeNode("Mercury");
    root.add(mercury);//from ww w .j a  va 2  s.c  o  m
    DefaultMutableTreeNode venus = new DefaultMutableTreeNode("Venus");
    root.add(venus);
    DefaultMutableTreeNode mars = new DefaultMutableTreeNode("Mars");
    root.add(mars);
    JTree tree = new JTree(root);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

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

    DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH);

    String days[] = symbols.getWeekdays();
    SpinnerModel model1 = new SpinnerListModel(days);
    JSpinner spinner1 = new JSpinner(model1);

    JLabel label1 = new JLabel("French Days/List");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.NORTH);

    frame.setSize(200, 90);/*from  w w w  .  ja  v  a 2  s . c  o m*/
    frame.setVisible(true);
}

From source file:InternalFrameListenerDemo.java

public static void main(final String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JDesktopPane desktop = new JDesktopPane();
    JInternalFrame internalFrame = new JInternalFrame("Can Do All", true, true, true, true);

    desktop.add(internalFrame);//from w w  w  . j a  va  2  s .  c  om

    internalFrame.setBounds(25, 25, 200, 100);

    JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER);
    internalFrame.add(label, BorderLayout.CENTER);

    internalFrame.setVisible(true);

    internalFrame.addInternalFrameListener(new InternalFrameListener() {

        public void internalFrameClosing(InternalFrameEvent e) {
            displayMessage("Internal frame closing", e);
        }

        public void internalFrameClosed(InternalFrameEvent e) {
            displayMessage("Internal frame closed", e);
        }

        public void internalFrameOpened(InternalFrameEvent e) {
            displayMessage("Internal frame opened", e);
        }

        public void internalFrameIconified(InternalFrameEvent e) {
            displayMessage("Internal frame iconified", e);
        }

        public void internalFrameDeiconified(InternalFrameEvent e) {
            displayMessage("Internal frame deiconified", e);
        }

        public void internalFrameActivated(InternalFrameEvent e) {
            displayMessage("Internal frame activated", e);
        }

        public void internalFrameDeactivated(InternalFrameEvent e) {
            displayMessage("Internal frame deactivated", e);
        }

        void displayMessage(String prefix, InternalFrameEvent e) {
            System.out.println(prefix + ": " + e.getSource());
        }

    });

    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);

    frame.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
}

From source file:SimpleTableSample.java

public static void main(String args[]) {
    Object rows[][] = { { "one", "ichi - \u4E00" }, { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" },
            { "four", "shi - \u56DB" }, { "five", "go - \u4E94" }, { "six", "roku - \u516D" },
            { "seven", "shichi - \u4E03" }, { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" },
            { "ten", "ju - \u5341" } };
    Object headers[] = { "English", "Japanese" };
    String title = (args.length == 0 ? "JTable Sample" : args[0]);
    JFrame frame = new JFrame(title);
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);//from  w  ww .java 2  s. c o m
    frame.setVisible(true);
}

From source file:InternalFrameTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Internal Frame Listener");
    Container contentPane = frame.getContentPane();
    JLayeredPane desktop = new JDesktopPane();
    desktop.setOpaque(false);//from  w  ww  .  ja  v a 2s. c o m
    desktop.add(createLayer("One"), JLayeredPane.POPUP_LAYER);
    desktop.add(createLayer("Two"), JLayeredPane.DEFAULT_LAYER);
    desktop.add(createLayer("Three"), JLayeredPane.PALETTE_LAYER);
    contentPane.add(desktop, BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.show();
}

From source file:CutPasteSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Cut/Paste Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();

    JTextField textField = new JTextField();
    JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);

    content.add(textField, BorderLayout.NORTH);
    content.add(scrollPane, BorderLayout.CENTER);

    Action actions[] = textField.getActions();

    Action cutAction = TextUtilities.findAction(actions, DefaultEditorKit.cutAction);
    Action copyAction = TextUtilities.findAction(actions, DefaultEditorKit.copyAction);
    Action pasteAction = TextUtilities.findAction(actions, DefaultEditorKit.pasteAction);

    JPanel panel = new JPanel();
    content.add(panel, BorderLayout.SOUTH);

    JButton cutButton = new JButton(cutAction);
    cutButton.setText("Cut");
    panel.add(cutButton);//from   www  .j a  v a  2s.  c  o m

    JButton copyButton = new JButton(copyAction);
    copyButton.setText("Copy");
    panel.add(copyButton);

    JButton pasteButton = new JButton(pasteAction);
    pasteButton.setText("Paste");
    panel.add(pasteButton);

    frame.setSize(250, 250);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);/* w w w  .ja  va 2s. c om*/
    for (int j = 0; j < 5; j++) {
        model.addElement(labels[j]);
    }
    model.trimToSize();

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

    frame.setSize(300, 350);
    frame.setVisible(true);
}