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

public static void addNewLineTo(Container container) {
    JLabel label = new JLabel();
    label.setPreferredSize(new Dimension(SCREEN_SIZE.width, 0));
    container.add(label);
}

From source file:layout.BoxLayoutDemo.java

private static void addAButton(String text, Container container) {
    JButton button = new JButton(text);
    button.setAlignmentX(Component.CENTER_ALIGNMENT);
    container.add(button);
}

From source file:layout.SpringDemo1.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread./* ww  w.  ja va  2s  .co m*/
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("SpringDemo1");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Set up the content pane.
    Container contentPane = frame.getContentPane();
    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);
    contentPane.add(new JLabel("Label: "));
    contentPane.add(new JTextField("Text field", 15));

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

From source file:GridLayoutDemo.java

public static void addComponentsToPane(Container pane) {
    if (RIGHT_TO_LEFT) {
        pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    }/*from  w ww.  ja v  a2 s  .c  o  m*/

    pane.setLayout(new GridLayout(0, 2));

    pane.add(new JButton("Button 1"));
    pane.add(new JButton("Button 2"));
    pane.add(new JButton("Button 3"));
    pane.add(new JButton("Long-Named Button 4"));
    pane.add(new JButton("5"));
}

From source file:layout.BorderLayoutDemo.java

public static void addComponentsToPane(Container pane) {

    if (!(pane.getLayout() instanceof BorderLayout)) {
        pane.add(new JLabel("Container doesn't use BorderLayout!"));
        return;//w ww .j  a  va 2  s. co  m
    }

    if (RIGHT_TO_LEFT) {
        pane.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
    }

    JButton button = new JButton("Button 1 (PAGE_START)");
    pane.add(button, BorderLayout.PAGE_START);

    //Make the center component big, since that's the
    //typical usage of BorderLayout.
    button = new JButton("Button 2 (CENTER)");
    button.setPreferredSize(new Dimension(200, 100));
    pane.add(button, BorderLayout.CENTER);

    button = new JButton("Button 3 (LINE_START)");
    pane.add(button, BorderLayout.LINE_START);

    button = new JButton("Long-Named Button 4 (PAGE_END)");
    pane.add(button, BorderLayout.PAGE_END);

    button = new JButton("5 (LINE_END)");
    pane.add(button, BorderLayout.LINE_END);
}

From source file:SpringDemo1.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*  w w  w  .  jav  a  2s  .co  m*/
private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new JFrame("SpringDemo1");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Set up the content pane.
    Container contentPane = frame.getContentPane();
    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);
    contentPane.add(new JLabel("Label: "));
    contentPane.add(new JTextField("Text field", 15));

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

From source file:Main.java

/** 
 * Creates a <code>JSpinner</code> with the specified label text from the given
 * <code>SpinnerModel</code> and adds the <code>JSpinner</code> to the given 
 * <code>Container</code>./* ww  w .j  a v a2 s  . com*/
 * @param c - the container to add the spinner to
 * @param label - the text which to add to the spinner
 * @param model - the <code>SpinnerModel</code> to make the spinner from
 * @return a JSpinner created from the <code>SpinnerModel</code> with the 
 * specified label text
 */
public static JSpinner addLabeledSpinner(Container c, String label, SpinnerModel model) {
    JLabel l = new JLabel(label);
    c.add(l);

    JSpinner spinner = new JSpinner(model);
    l.setLabelFor(spinner);
    c.add(spinner);

    return spinner;
}

From source file:Main.java

public static void add(final Component component, final Container container) {
    if (component != null && container != null) {
        if (SwingUtilities.isEventDispatchThread()) {
            container.add(component);
        } else {/*from   w ww .  j a  v  a  2s .c om*/
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        container.add(component);
                    }
                });
            } catch (InterruptedException | InvocationTargetException e) {

            }
        }
    }
}

From source file:components.SpinnerDemo.java

static protected JSpinner addLabeledSpinner(Container c, String label, SpinnerModel model) {
    JLabel l = new JLabel(label);
    c.add(l);

    JSpinner spinner = new JSpinner(model);
    l.setLabelFor(spinner);/*from   ww  w .  ja  v  a  2s. c  om*/
    c.add(spinner);

    return spinner;
}

From source file:Main.java

public static void addNewLineTo(Container container, int lineHeight) {
    JLabel label = new JLabel();
    label.setPreferredSize(new Dimension(SCREEN_SIZE.width, lineHeight));
    label.setBorder(new LineBorder(Color.BLACK));
    container.add(label);
}