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

public static void main(String args[]) {
    JFrame horizontalFrame = new JFrame("Horizontal");
    horizontalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Box horizontalBox = Box.createHorizontalBox();
    horizontalBox.add(new JLabel("Left"));
    horizontalBox.add(new JTextField("Middle"));
    horizontalBox.add(new JButton("Right"));
    horizontalFrame.add(horizontalBox, BorderLayout.CENTER);
    horizontalFrame.setSize(150, 150);/*  w  w w . j  a  v a  2 s. c  om*/
    horizontalFrame.setVisible(true);
}

From source file:ListSample.java

public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };

    String title = "JList Sample";
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList list = new JList(labels);
    JScrollPane scrollPane = new JScrollPane(list);

    Container contentPane = f.getContentPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);

    f.setSize(200, 200);//w  w  w  .  j  a  v a2  s. co  m
    f.setVisible(true);
}

From source file:MyLabel.java

public static void main(String[] args) {
    String lyrics = "<html>Line<br>line<br>line</html>";

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(10, 10));

    JLabel label = new JLabel(lyrics);
    label.setFont(new Font("Georgia", Font.PLAIN, 14));
    label.setForeground(new Color(50, 50, 25));

    panel.add(label, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    JFrame f = new JFrame();
    f.add(panel);/*  w  w  w  . j a v a 2 s  .  c  o  m*/
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:MainFrameBorderLayout.java

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

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.BEFORE_FIRST_LINE);

    frame.add(outerPanel);/*www.jav  a 2 s  . c  o m*/
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File sourceimage = new File("source.gif");
    Image image = ImageIO.read(sourceimage);

    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();//w  w  w . j  a va 2  s .  c  o  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel ui = new JPanel(new BorderLayout(20, 20));

    ui.setBorder(new LineBorder(Color.RED, 1));

    JTextField fileName = new JTextField();
    ui.add(fileName, BorderLayout.NORTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 0, 10, 30));
    ui.add(buttonPanel, BorderLayout.CENTER);

    JButton creater = new JButton("Create File");
    buttonPanel.add(creater);/*  w  ww. j a v  a  2s  .c o  m*/
    JButton deleter = new JButton("Delete File");
    buttonPanel.add(deleter);

    JOptionPane.showMessageDialog(null, ui);

}

From source file:Main.java

public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H" };
    JFrame frame = new JFrame("Selecting JList");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList jlist = new JList(labels);
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1, BorderLayout.CENTER);

    ListSelectionListener listSelectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            System.out.println("First index: " + listSelectionEvent.getFirstIndex());
            System.out.println(", Last index: " + listSelectionEvent.getLastIndex());
            boolean adjust = listSelectionEvent.getValueIsAdjusting();
            System.out.println(", Adjusting? " + adjust);
            if (!adjust) {
                JList list = (JList) listSelectionEvent.getSource();
                int selections[] = list.getSelectedIndices();
                Object selectionValues[] = list.getSelectedValues();
                for (int i = 0, n = selections.length; i < n; i++) {
                    if (i == 0) {
                        System.out.println(" Selections: ");
                    }/* w w  w  .  j av  a 2s .  c  om*/
                    System.out.println(selections[i] + "/" + selectionValues[i] + " ");
                }
            }
        }
    };
    jlist.addListSelectionListener(listSelectionListener);

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

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button = new JButton("Pick to Change Background");
    Color myBlack = new Color(0, 0, 0); // Color black
    //    Color myWhite = new Color(255,255,255);     // Color white
    //  Color myGreen = new Color(0,200,0);         // A shade of green

    button.setBackground(myBlack);//from  ww  w  . j av a 2 s .  c o  m
    f.add(button, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

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

    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);

    JTextField textField = new JTextField();
    label.setLabelFor(textField);/*ww w . j av  a 2 s .co  m*/

    frame.add(label, BorderLayout.WEST);
    frame.add(textField, BorderLayout.CENTER);

    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 100);
    frame.setVisible(true);
}

From source file:Main.java

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

    JProgressBar bar = new JProgressBar(JProgressBar.VERTICAL);
    bar.setEnabled(true);//w  w  w  .j a  va2 s.  c  o  m

    bar.setBackground(Color.YELLOW);
    bar.setForeground(Color.GREEN);

    bar.setStringPainted(true);
    bar.setString("2000 g");
    bar.setValue(65);
    frame.setLayout(new BorderLayout());
    frame.add(bar, BorderLayout.CENTER);
    frame.setSize(500, 400);
    frame.setVisible(true);
}