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

public static void main(String[] args) {
    JFrame frame = new JFrame("VoteDialog");

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 1));
    contentPane.add(new VoteDialog(frame));

    // Exit when the window is closed.
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.pack();/*from  w  ww  . ja  v a2 s  .c o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.pack();/*from   w ww. j  a  v  a2s.  co m*/

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(null);
    for (int i = 0; i < 4; i++) {
        JPanel panel = new JPanel();
        panel.setBounds((i * 75) + 475, 25, 75, 100);
        System.out.println(panel.getBounds());
        contentPane.add(panel);
        panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3));
    }
    System.out.println(getComponentAt(contentPane, new Point(475, 25)));
    System.out.println(getComponentAt(contentPane, new Point(100, 25)));
    frame.setVisible(true);
}

From source file:TrySpringLayout.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Spring Layout");
    aWindow.setBounds(30, 30, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout layout = new SpringLayout();
    Container content = aWindow.getContentPane();
    content.setLayout(layout);/*from w ww.j a va2  s . c o  m*/
    JButton[] buttons = new JButton[6];
    SpringLayout.Constraints constr = null;
    for (int i = 0; i < buttons.length; i++) {
        buttons[i] = new JButton("Press " + (i + 1));
        content.add(buttons[i]);
    }
    Spring xSpring = Spring.constant(5, 15, 25);
    Spring ySpring = Spring.constant(10, 30, 50);
    constr = layout.getConstraints(buttons[0]);
    constr.setX(xSpring);
    constr.setY(ySpring);
    // Hook buttons together with springs
    for (int i = 1; i < buttons.length; i++) {
        constr = layout.getConstraints(buttons[i]);
        layout.putConstraint(SpringLayout.WEST, buttons[i], xSpring, SpringLayout.EAST, buttons[i - 1]);
        layout.putConstraint(SpringLayout.NORTH, buttons[i], ySpring, SpringLayout.SOUTH, buttons[i - 1]);
    }
    aWindow.setVisible(true); // Display the window
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Layout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    int horizontalGap = 20;
    int verticalGap = 10;
    Container contentPane = frame.getContentPane();
    FlowLayout flowLayout = new FlowLayout(FlowLayout.LEADING, horizontalGap, verticalGap);
    contentPane.setLayout(flowLayout);/*from   w ww  .j  a  va2 s.  c  o m*/
    frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

    for (int i = 1; i <= 5; i++) {
        contentPane.add(new JButton("Button  " + i));
    }
    frame.pack();
    frame.setVisible(true);
}

From source file:WorldMapGraphDemo.java

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

From source file:MainClass.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Spring Layout");
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setSize(500, 500);//from   w w  w  . j av  a 2  s  . c o  m
    SpringLayout layout = new SpringLayout();
    Container content = aWindow.getContentPane();
    content.setLayout(layout);

    JButton[] buttons = new JButton[6];
    SpringLayout.Constraints constr = null;
    for (int i = 0; i < buttons.length; i++) {
        buttons[i] = new JButton("Press " + (i + 1));
        content.add(buttons[i]);
    }

    Spring xSpring = Spring.constant(5, 15, 25);
    Spring ySpring = Spring.constant(10, 30, 50);

    constr = layout.getConstraints(buttons[0]);
    constr.setX(xSpring);
    constr.setY(ySpring);

    for (int i = 1; i < buttons.length; i++) {
        constr = layout.getConstraints(buttons[i]);
        layout.putConstraint(SpringLayout.WEST, buttons[i], xSpring, SpringLayout.EAST, buttons[i - 1]);
        layout.putConstraint(SpringLayout.NORTH, buttons[i], ySpring, SpringLayout.SOUTH, buttons[i - 1]);
    }
    aWindow.setVisible(true); // Display the window
}

From source file:TextFormat.java

public static void main(String[] args) {
    JFrame jf = new JFrame("Demo");
    Container cp = jf.getContentPane();
    TextFormat tl = new TextFormat();
    tl.setFont(new Font("SansSerif", Font.BOLD, 42));
    tl.setText("The quick brown fox jumped over the lazy cow");
    cp.add(tl);
    jf.setSize(300, 200);/* w  w w.  ja  v  a2  s  . co  m*/
    jf.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sharing Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();
    JTextArea textarea1 = new JTextArea();
    Document document = textarea1.getDocument();
    JTextArea textarea2 = new JTextArea(document);
    JTextArea textarea3 = new JTextArea(document);
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(new JScrollPane(textarea1));
    content.add(new JScrollPane(textarea2));
    content.add(new JScrollPane(textarea3));
    frame.setSize(300, 400);//from w  w  w  . j a  v  a 2  s .  c om
    frame.setVisible(true);
}

From source file:AlignX.java

public static void main(String args[]) {
    JFrame frame = new JFrame("X Alignment");
    Container contentPane = frame.getContentPane();

    Container panel1 = makeIt("R", Component.RIGHT_ALIGNMENT);
    Container panel2 = makeIt("C", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("L", Component.LEFT_ALIGNMENT);

    contentPane.setLayout(new FlowLayout());
    contentPane.add(panel1);
    contentPane.add(panel2);//from ww w.  jav  a2 s .co  m
    contentPane.add(panel3);

    frame.pack();
    frame.show();
}

From source file:BoxLayoutManagerContainerTest.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);/* w  ww  .  jav  a 2 s.c  o  m*/
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    for (float align = 0.0f; align <= 1.0f; align += 0.25f) {
        JTextField tf = new JTextField("X Alignment = " + align, 10);
        tf.setAlignmentX(align);
        pane.add(tf);
    }
    f.setSize(400, 300);
    f.setVisible(true);
}