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 void add(Component comp, Object constraints) 

Source Link

Document

Adds the specified component to the end of this container.

Usage

From source file:Main.java

private static void addComponent(Container container, Component component, int gridx, int gridy, int gridwidth,
        int gridheight, int anchor, int fill) {
    Insets insets = new Insets(0, 0, 0, 0);
    GridBagConstraints gbc = new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 1.0, 1.0, anchor, fill,
            insets, 0, 0);//from  w  w  w.  j a  v a  2  s . c om
    container.add(component, gbc);
}

From source file:Main.java

/**
 * Helper method that taked a component and adds it to a container using
 * {@link java.awt.GridBagConstraints}./*  w ww. jav a2 s  .  co  m*/
 * @param container The container to add to.
 * @param component The componend to be added.
 * @param gridx GridBagConstraints value.
 * @param gridy GridBagConstraints value.
 * @param fill GridBagConstraints value.
 */
public static void addWithLesserGridBagConstraints(final Container container, final Component component,
        final int gridx, final int gridy, final int fill) {
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = gridx;
    gridBagConstraints.gridy = gridy;
    gridBagConstraints.fill = fill;
    container.add(component, gridBagConstraints);
}

From source file:components.FrameDemo2.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread./*from  w w w  .j a v a2 s  .co m*/
 */
private static void createAndShowGUI() {
    //Use the Java look and feel.
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
    }

    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);

    //Instantiate the controlling class.
    JFrame frame = new JFrame("FrameDemo2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    FrameDemo2 demo = new FrameDemo2();

    //Add components to it.
    Container contentPane = frame.getContentPane();
    contentPane.add(demo.createOptionControls(), BorderLayout.CENTER);
    contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END);
    frame.getRootPane().setDefaultButton(defaultButton);

    //Display the window.
    frame.pack();
    frame.setLocationRelativeTo(null); //center it
    frame.setVisible(true);
}

From source file:geva.Operator.Operations.UserSelect.java

/**
 * Helper for adding a control to a GridBagLayout control
 * @param container The control to add <var>control</var> to
 * @param control The control being added to <var>container</var>
 * @param gridX The grid column to add the control
 * @param gridY The grid row to add the control
 * @param gridW The number of columns to span
 * @param gridH The number of rows to span
 * @param weightX The amount of horizontal space this column should take
 *  relative to other columns/*from w  ww. j  av  a 2s .c  om*/
 * @param weightY The amount of vertical space this column should take
 *  relative to other rows
 */
protected static void gridAdd(Container container, Container control, int gridX, int gridY, int gridW,
        int gridH, double weightX, double weightY) {
    container.add(control, new GridBagConstraints(gridX, gridY, gridW, gridH, weightX, weightY,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
}

From source file:FrameDemo2.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*  w w w .ja v  a2  s  .com*/
private static void createAndShowGUI() {
    // Use the Java look and feel.
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
    }

    // Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);

    // Instantiate the controlling class.
    JFrame frame = new JFrame("FrameDemo2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    FrameDemo2 demo = new FrameDemo2();

    // Add components to it.
    Container contentPane = frame.getContentPane();
    contentPane.add(demo.createOptionControls(), BorderLayout.CENTER);
    contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END);
    frame.getRootPane().setDefaultButton(defaultButton);

    // Display the window.
    frame.pack();
    frame.setLocationRelativeTo(null); // center it
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Adds all of the specified {@link Component components} with the given
 * constraints, then calls {@link #validate(Container)} on <tt>to</tt>.
 * //  w  w  w . j  a  v a 2  s  .  c o  m
 * @param to
 *            - the {@link Container} to add to
 * @param comps
 *            - the components to add
 * @param constraints
 *            - the constraints. If <tt>null</tt>, a new array of size
 *            <tt>comps.length</tt> is created.
 * @see #validate(Container)
 */
public static void addAllAndValidate(Container to, Component[] comps, Object[] constraints) {
    if (constraints == null) {
        constraints = new Object[comps.length];
    } else if (constraints.length < comps.length) {
        constraints = Arrays.copyOf(constraints, comps.length);
    }
    for (int i = 0; i < comps.length; i++) {
        to.add(comps[i], constraints[i]);
    }
    validate(to);
}

From source file:edu.mbl.jif.datasetconvert.CheckboxTreeDimensions.java

public static void test() {
    JSONObject sumMD = SumMetadata.newSummaryMetadata("", "", new ImageAttributes(100, 100),
            new String[] { "Aniso", "Orient", "Sample0", "Sample1" }, 5, 10, 1, "source", "comment");
    final CheckboxTreeDimensions tree = new CheckboxTreeDimensions(sumMD);
    QuickFrame f = new QuickFrame("Test");

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(300, 600);/*from ww  w .java2  s. c  o  m*/
    Container jContentPane = new JPanel();
    jContentPane.setLayout(new BorderLayout());
    JScrollPane cbt = tree.getCheckboxTree();
    cbt.setPreferredSize(new Dimension(200, 400));
    jContentPane.add(cbt, BorderLayout.CENTER);

    JButton buttonTest = new JButton("test");
    buttonTest.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tree.getSelectedIndices();
        }
    });
    jContentPane.add(buttonTest, BorderLayout.SOUTH);
    f.setContentPane(jContentPane);
    f.setTitle("CheckboxTree");
    f.pack();
    f.setVisible(true);

}

From source file:JListBackground.java

public static void addComponentsToPane(Container pane) {
    String[] bruteForceCode = { "int count = 0", "int m = mPattern.length();", "int n = mSource .length();",
            "outer:", " ++count;", " }", " return count;", "}" };
    JList list = new JList(bruteForceCode);
    Border etch = BorderFactory.createEtchedBorder();
    list.setBorder(BorderFactory.createTitledBorder(etch, "Brute Force Code"));
    JPanel listPanel = new JPanel();
    listPanel.add(list);/* ww  w .  j  a  va 2s.  c  om*/
    listPanel.setBackground(lightBlue);
    list.setBackground(lightBlue);

    pane.add(listPanel, BorderLayout.CENTER);
    pane.setBackground(lightBlue);
}

From source file:Main.java

/**
 * Helper method that taked a component and adds it to a container using
 * {@link java.awt.GridBagConstraints}./*from w w  w  .  j  a v  a2 s.c o m*/
 * @param container The container to add to.
 * @param component The componend to be added.
 * @param gridx GridBagConstraints value.
 * @param gridy GridBagConstraints value.
 * @param weightx GridBagConstraints value.
 * @param weighty GridBagConstraints value.
 * @param fill GridBagConstraints value.
 * @param insets GridBagConstraints value.
 */
public static void addWithGridBagConstraints(final Container container, final Component component,
        final int gridx, final int gridy, final double weightx, final double weighty, final int fill,
        final Insets insets) {
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = gridx;
    gridBagConstraints.gridy = gridy;
    gridBagConstraints.weightx = weightx;
    gridBagConstraints.weighty = weighty;
    gridBagConstraints.fill = fill;
    gridBagConstraints.insets = insets;
    container.add(component, gridBagConstraints);
}

From source file:GridBagLayoutDemo.java

public static void addComponentsToPane(Container pane) {
    if (RIGHT_TO_LEFT) {
        pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    }//from  ww  w .  j a  v  a2 s  .  c  om

    JButton button;
    pane.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    if (shouldFill) {
        // natural height, maximum width
        c.fill = GridBagConstraints.HORIZONTAL;
    }

    button = new JButton("Button 1");
    if (shouldWeightX) {
        c.weightx = 0.5;
    }
    c.gridx = 0;
    c.gridy = 0;
    pane.add(button, c);

    button = new JButton("Button 2");
    c.gridx = 1;
    c.gridy = 0;
    pane.add(button, c);

    button = new JButton("Button 3");
    c.gridx = 2;
    c.gridy = 0;
    pane.add(button, c);

    button = new JButton("Long-Named Button 4");
    c.ipady = 40; // make this component tall
    c.weightx = 0.0;
    c.gridwidth = 3;
    c.gridx = 0;
    c.gridy = 1;
    pane.add(button, c);

    button = new JButton("5");
    c.ipady = 0; // reset to default
    c.weighty = 1.0; // request any extra vertical space
    c.anchor = GridBagConstraints.PAGE_END; // bottom of space
    c.insets = new Insets(10, 0, 0, 0); // top padding
    c.gridx = 1; // aligned with button 2
    c.gridwidth = 2; // 2 columns wide
    c.gridy = 2; // third row
    pane.add(button, c);
}