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

public static void main(String[] args) {
    JFrame f = new JFrame("Vertical BoxLayout-managed container");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = new BoxPanel();
    f.setContentPane(pane);/*from   w w  w  .  ja v a2  s. c  om*/
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    for (float align = 0.0f; align <= 1.0f; align += 0.25f) {
        JButton button = new JButton("X Alignment = " + align);
        button.setAlignmentX(align);
        pane.add(button);
        pane.add(Box.createVerticalGlue());
    }
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    Container container = frame.getContentPane();

    GridBagLayout gbl = new GridBagLayout();

    container.setLayout(gbl);/*from www .  java2 s  . c om*/

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 1;

    JButton component = new JButton("a");

    gbl.setConstraints(component, gbc);

    container.add(component);

    frame.pack();
    frame.setVisible(true);
}

From source file:bigdata.explorer.nutch.grapview.tests.WebGraphTreeLayout.java

/**
 * a driver for this demo/*from   ww w . j a  v  a  2  s .  c o  m*/
 */
public static void main(String[] args) throws IOException {
    JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    content.add(new WebGraphTreeLayout());
    frame.pack();
    frame.setVisible(true);
}

From source file:SpringDemo2.java

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

    // Set up the content pane.
    Container contentPane = frame.getContentPane();
    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);/*from w ww  . j a v  a  2s  .  co  m*/

    // Create and add the components.
    JLabel label = new JLabel("Label: ");
    JTextField textField = new JTextField("Text field", 15);
    contentPane.add(label);
    contentPane.add(textField);

    // Adjust constraints for the label so it's at (5,5).
    layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane);

    // Adjust constraints for the text field so it's at
    // (<label's right edge> + 5, 5).
    layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label);
    layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:ActionButtonSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String command = actionEvent.getActionCommand();
            System.out.println("Selected: " + command);
        }//from w ww.j  a  v a  2s  . c om
    };

    Container content = frame.getContentPane();
    content.setLayout(new GridLayout(2, 2));

    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    button1.setActionCommand("First");
    button1.addActionListener(actionListener);
    content.add(button1);

    Icon warnIcon = new ImageIcon("Warn.gif");
    JButton button2 = new JButton(warnIcon);
    button2.setActionCommand("Second");
    button2.addActionListener(actionListener);
    content.add(button2);

    JButton button3 = new JButton("Warning", warnIcon);
    button3.setActionCommand("Third");
    button3.addActionListener(actionListener);
    content.add(button3);

    String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
            + "<font color=\"#FF0080\"><u>Multi-line</u></font>";
    JButton button4 = new JButton(htmlButton);
    button4.setActionCommand("Fourth");
    button4.addActionListener(actionListener);
    content.add(button4);

    JRootPane rootPane = frame.getRootPane();
    rootPane.setDefaultButton(button2);

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

From source file:GrafosTroleBus.java

/**
 * a driver for this demo//from  w  w w  . jav a 2 s  . c  o  m
 */
public static void main(String[] args) {
    // create a frame to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    content.add(new GrafosTroleBus());
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:SpringDemo3.java

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

    // Set up the content pane.
    Container contentPane = frame.getContentPane();
    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);/* www  .j a  va2  s  .  c  om*/

    // Create and add the components.
    JLabel label = new JLabel("Label: ");
    JTextField textField = new JTextField("Text field", 15);
    contentPane.add(label);
    contentPane.add(textField);

    // Adjust constraints for the label so it's at (5,5).
    layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane);

    // Adjust constraints for the text field so it's at
    // (<label's right edge> + 5, 5).
    layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label);
    layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane);

    // Adjust constraints for the content pane: Its right
    // edge should be 5 pixels beyond the text field's right
    // edge, and its bottom edge should be 5 pixels beyond
    // the bottom edge of the tallest component (which we'll
    // assume is textField).
    layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, textField);
    layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, textField);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:VerticalBoxLayoutManagerContainerTest.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = new BoxPanel();
    f.setContentPane(pane);//from  w  w  w  .j  a va  2  s  . c om
    BoxLayout bl = new BoxLayout(pane, BoxLayout.Y_AXIS);
    pane.setLayout(bl);
    for (float align = 0.0f; align <= 1.0f; align += 0.25f) {
        JButton button = new JButton("X Alignment = " + align);
        button.setAlignmentX(align);
        pane.add(button);
        pane.add(Box.createRigidArea(new Dimension(0, 15)));
    }
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:CalIcon.java

public static void main(String[] args) {
    JFrame jf = new JFrame("Calendar");
    Container cp = jf.getContentPane();
    cp.setLayout(new GridLayout(0, 1, 5, 5));
    CalIcon c = new CalIcon(true);
    cp.add(c);
    JButton j = new JButton("As Icon", new CalIcon(false));
    cp.add(j);/* ww  w .  j av  a  2  s .  c  om*/
    jf.pack();
    jf.setVisible(true);
}

From source file:TreeLayoutDemo.java

/**
 * a driver for this demo//from   w ww  .  j  av a2  s . co m
 */
public static void main(String[] args) {
    JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    content.add(new TreeLayoutDemo());
    frame.pack();
    frame.setVisible(true);
}