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

public void init() {
    cb1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            trace("1", cb1);
        }/*ww w. j a  v a2  s.  c  om*/
    });
    cb2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            trace("2", cb2);
        }
    });
    cb3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            trace("3", cb3);
        }
    });
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(new JScrollPane(t));
    cp.add(cb1);
    cp.add(cb2);
    cp.add(cb3);
}

From source file:GridSizeTest.java

public GridSizeTest() {
    Container pane = getContentPane();
    pane.setLayout(new GridLayout(2, 2));
    JButton button = new JButton("First");
    pane.add(button);
    button = new JButton("Second with a very long name");
    pane.add(button);//  w  w  w .  j av  a 2s  .co  m
    button = new JButton("Hi");
    button.setFont(new Font("Courier", Font.PLAIN, 36));
    pane.add(button);
    button = new JButton("There");
    pane.add(button);
}

From source file:BufferedImageMouseDrag.java

public BufferedImageMouseDrag() {
    super();//  w w  w  . j  a  v  a2s  . co m
    Container container = getContentPane();

    canvas = new DisplayCanvas();
    container.add(canvas);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(450, 400);
    setVisible(true);
}

From source file:Popup.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(t);
    ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            t.setText(((JMenuItem) e.getSource()).getText());
        }//from  ww w.j a v a  2 s  .com
    };
    JMenuItem m = new JMenuItem("Hither");
    m.addActionListener(al);
    popup.add(m);
    m = new JMenuItem("Yon");
    m.addActionListener(al);
    popup.add(m);
    m = new JMenuItem("Afar");
    m.addActionListener(al);
    popup.add(m);
    popup.addSeparator();
    m = new JMenuItem("Stay Here");
    m.addActionListener(al);
    popup.add(m);
    PopupListener pl = new PopupListener();
    addMouseListener(pl);
    t.addMouseListener(pl);
}

From source file:SwingSpinnerTest.java

public SwingSpinnerTest() {
    super("JSpinner Test");
    setSize(300, 180);//from w  ww  . j  a  v  a 2s .c  o m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new GridLayout(0, 2));

    c.add(new JLabel(" Basic Spinner"));
    c.add(new JSpinner());

    c.add(new JLabel(" Date Spinner"));
    c.add(new JSpinner(new SpinnerDateModel()));

    String weekdays[] = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
            "Saturday" };
    c.add(new JLabel(" List Spinner"));
    c.add(new JSpinner(new SpinnerListModel(weekdays)));

    c.add(new JLabel(" Number Spinner"));
    c.add(new JSpinner(new SpinnerNumberModel(0, 0, 100, 5)));

    c.add(new JLabel(" Rollover List Spinner"));
    c.add(new JSpinner(new RolloverSpinnerListModel(weekdays)));

    setVisible(true);
}

From source file:SystemFontDisplayer.java

public SystemFontDisplayer() {
    Container container = getContentPane();
    displayPanel = new DisplayPanel();
    container.add(displayPanel);
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new GridLayout(1, 3));

    fontsBox = new JComboBox(displayPanel.fontFamilyNames);
    fontsBox.setSelectedItem("Arial");
    fontsBox.addActionListener(new ComboBoxListener());

    fontStylesBox.addActionListener(new ComboBoxListener());

    fontSizesBox.setSelectedItem("36");
    fontSizesBox.addActionListener(new ComboBoxListener());
    controlPanel.add(fontsBox);/*  ww  w. j  av a2 s.c  o m*/
    controlPanel.add(fontStylesBox);
    controlPanel.add(fontSizesBox);
    container.add(BorderLayout.SOUTH, controlPanel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setSize(400, 250);
    setVisible(true);
}

From source file:LookAndFeel.java

public LookAndFeel() {
    super("Look And Feel");
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    for (int i = 0; i < samples.length; i++)
        cp.add(samples[i]);
}

From source file:BusinessLogic.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(t);
    calc1.addActionListener(new Calc1L());
    calc2.addActionListener(new Calc2L());
    JPanel p1 = new JPanel();
    p1.add(calc1);//from   ww  w  .j a  v a 2  s .c om
    p1.add(calc2);
    cp.add(p1);
    mod.getDocument().addDocumentListener(new ModL());
    JPanel p2 = new JPanel();
    p2.add(new JLabel("Modifier:"));
    p2.add(mod);
    cp.add(p2);
}

From source file:SaveDialog.java

/** Construct the object including its GUI */
public SaveDialog() {
    super("SaveDialog");
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(new Label("Press this button to see the Quit dialog: "));
    cp.add(quitButton = new Button("Quit"));
    quitButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("In Exit Button's action handler");
            if (okToQuit()) {
                setVisible(false);/*from w ww  . j  av a2s  .  co  m*/
                dispose();
                System.exit(0);
            }
        }
    });
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
            System.exit(0);
        }
    });

    pack();
}

From source file:DialogSeparator.java

public FlightReservation() {
    super("Dialog ");

    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    c.add(new DialogSeparator("Options"));

    ButtonGroup group = new ButtonGroup();
    JRadioButton r1 = new JRadioButton("First class");
    group.add(r1);//w ww .  j  av  a 2s . c  om
    c.add(r1);

    JRadioButton r2 = new JRadioButton("Business");
    group.add(r2);
    c.add(r2);

    JRadioButton r3 = new JRadioButton("Coach");
    group.add(r3);
    c.add(r3);

    c.add(new DialogSeparator());

    JButton b3 = new JButton("Exit");
    c.add(b3);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

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