Example usage for java.awt Container add

List of usage examples for java.awt Container add

Introduction

In this page you can find the example usage for java.awt Container add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:MyDialog.java

public MyDialog(JFrame parent) {
    super(parent, "My dialog", true);
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(new JLabel("Here is my dialog"));
    JButton ok = new JButton("OK");
    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dispose(); // Closes the dialog
        }/* w  w  w  . j  a v a  2 s  .  c  o  m*/
    });
    cp.add(ok);
    setSize(150, 125);
}

From source file:Main.java

public Main() {
    super("Month Spinner");
    setSize(200, 100);/*from w w  w  . jav  a  2s .  co  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));

    c.add(new JLabel("Expiration Date:"));
    Date today = new Date();
    SpinnerDateModel model = new SpinnerDateModel(today, null, null, Calendar.MONTH);
    JSpinner s = new JSpinner();
    s.setModel(model);
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
    s.setEditor(de);

    c.add(s);

    setVisible(true);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField field1 = new JTextField("Life's a drag", 20);
    JTextField field2 = new JTextField("and then you drop", 20);
    field1.setDragEnabled(true);//from   w ww.java2 s  . com
    field2.setDragEnabled(true);
    Container content = getContentPane();

    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(field1);
    content.add(field2);

    pack();
}

From source file:DragDropText.java

public DragDropText() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField field1 = new JTextField("Life's a drag", 20);
    JTextField field2 = new JTextField("and then you drop", 20);
    field1.setDragEnabled(true);/*from w w  w.  j  a v a2 s .  c o m*/
    field2.setDragEnabled(true);
    Container content = getContentPane();

    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(field1);
    content.add(field2);

    pack();
}

From source file:MainClass.java

public MainClass() {
    super("MainClass");

    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(new JButton("OK"));
    contentPane.add(new JButton("Cancel"));

    applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT);
}

From source file:Main.java

public Main() {
    super("Main");

    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(new JButton("OK"));
    contentPane.add(new JButton("Cancel"));

    applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT);
}

From source file:FlowLayout1.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    for (int i = 0; i < 20; i++)
        cp.add(new JButton("Button " + i));
}

From source file:Main.java

public Main() {
    super("Month Spinner");
    setSize(200, 100);//from   ww  w  . j  a va  2  s.  co  m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));

    c.add(new JLabel("Expiration Date:"));
    Date today = new Date();
    JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
    s.setEditor(de);
    c.add(s);

    setVisible(true);

    try {
        s.commitEdit();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:ComboBoxes.java

public void init() {
    for (int i = 0; i < 4; i++)
        c.addItem(description[count++]);
    t.setEditable(false);/*w  w  w.  j ava2  s. co m*/
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (count < description.length)
                c.addItem(description[count++]);
        }
    });
    c.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            t.setText("index: " + c.getSelectedIndex() + "   " + ((JComboBox) e.getSource()).getSelectedItem());
        }
    });
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(t);
    cp.add(c);
    cp.add(b);
}

From source file:MonthSpinner.java

public MonthSpinner() {
    super("Month Spinner");
    setSize(200, 100);//from w w  w .j a va 2  s .c  om
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));

    c.add(new JLabel("Expiration Date:"));
    Date today = new Date();
    // Start the spinner today, but don't set a min or max date
    // The increment should be a month
    JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
    s.setEditor(de);
    c.add(s);

    setVisible(true);
}