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

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

    final DefaultComboBoxModel model = new DefaultComboBoxModel(labels);

    JFrame frame = new JFrame("Shared Data");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    JComboBox comboBox1 = new JComboBox(model);
    comboBox1.setEditable(true);//from w ww . ja v a 2 s  .c  om

    panel.add(comboBox1);
    frame.add(panel, BorderLayout.NORTH);

    JList jlist = new JList(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("New Added");
        }
    };
    button.addActionListener(actionListener);

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

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Background Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final ImageIcon imageIcon = new ImageIcon("draft.gif");
    JTextArea textArea = new JTextArea() {
        Image image = imageIcon.getImage();

        Image grayImage = GrayFilter.createDisabledImage(image);
        {/*w  w w.  j  a  v a2s.  co m*/
            setOpaque(false);
        }

        public void paint(Graphics g) {
            g.drawImage(grayImage, 0, 0, this);
            super.paint(g);
        }
    };
    JScrollPane scrollPane = new JScrollPane(textArea);
    Container content = frame.getContentPane();
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(250, 250);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("E");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*w  ww. ja va  2  s .c  o  m*/
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
        }
    };
    button.addActionListener(actionListener);

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

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//from w w w  .ja  va2 s.com
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            System.out.println(model.getIndexOf("A"));
        }
    };
    button.addActionListener(actionListener);

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

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//ww  w . j  a  v  a2  s.  c  o m
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            System.out.println(model.getSelectedItem());
        }
    };
    button.addActionListener(actionListener);

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

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*from w  ww . jav  a 2s. c o m*/
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            System.out.println(model.getSize());
        }
    };
    button.addActionListener(actionListener);

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

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//from  w w w.  j a va 2 s  .c o  m
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            model.insertElementAt("Z", 0);
        }
    };
    button.addActionListener(actionListener);

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

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//from  ww  w .  j a v  a 2 s .c  om
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            System.out.println(model.getElementAt(1));
        }
    };
    button.addActionListener(actionListener);

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

From source file:ALineBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Line Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border thinBorder = LineBorder.createBlackLineBorder();
    Border thickBorder = new LineBorder(Color.white, 12);
    Border roundedBorder = new LineBorder(Color.black, 12, true);
    JButton thinButton = new JButton("1 Pixel");
    thinButton.setBorder(thinBorder);//from w ww  . j  a  v  a2 s .  c om
    JButton thickButton = new JButton("12 Pixel");
    thickButton.setBorder(thickBorder);
    JButton roundedButton = new JButton("Rounded 12 Pixel");
    roundedButton.setBorder(roundedBorder);
    Container contentPane = frame.getContentPane();
    contentPane.add(thinButton, BorderLayout.NORTH);
    contentPane.add(thickButton, BorderLayout.CENTER);
    contentPane.add(roundedButton, BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js");

    String[] ops = { "+", "-", "*", "/" };

    JPanel gui = new JPanel(new BorderLayout(2, 2));
    JPanel labels = new JPanel(new GridLayout(0, 1));
    gui.add(labels, BorderLayout.WEST);
    labels.add(new JLabel("a"));
    labels.add(new JLabel("operand"));
    labels.add(new JLabel("b"));
    labels.add(new JLabel("="));

    JPanel controls = new JPanel(new GridLayout(0, 1));
    gui.add(controls, BorderLayout.CENTER);
    JTextField a = new JTextField(10);
    controls.add(a);//from  ww w .  jav  a2s  . c o m
    JComboBox operand = new JComboBox(ops);
    controls.add(operand);
    JTextField b = new JTextField(10);
    controls.add(b);
    JTextField output = new JTextField(10);
    controls.add(output);

    ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String expression = a.getText() + operand.getSelectedItem() + b.getText();
            try {
                Object result = engine.eval(expression);
                if (result == null) {
                    output.setText("Output was 'null'");
                } else {
                    output.setText(result.toString());
                }
            } catch (ScriptException se) {
                output.setText(se.getMessage());
            }
        }
    };

    operand.addActionListener(al);
    a.addActionListener(al);
    b.addActionListener(al);

    JOptionPane.showMessageDialog(null, gui);
}