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

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JRootPane root = f.getRootPane();
    Container content = root.getContentPane();
    content.add(new JButton("Hello"));
    f.pack();/*from w  w  w.  j ava  2s . c  om*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    Container pane = frame.getContentPane();
    pane.add(blackJTextPane());
    frame.setSize(800, 600);/*from   w w  w  .  j  a v a  2 s . c  o m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JRootPane root = f.getRootPane();
    Container content = root.getContentPane();
    content.add(new JButton("Hello"));

    f.pack();/*from   w w w  .  j a va2s  . c  om*/
    f.setVisible(true);

}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Positioned Titled Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    TitledBorder aboveTopBorder = BorderFactory.createTitledBorder("AboveTop");
    aboveTopBorder.setTitlePosition(TitledBorder.ABOVE_TOP);
    JButton aboveTopButton = new JButton();
    aboveTopButton.setBorder(aboveTopBorder);
    Container contentPane = frame.getContentPane();
    contentPane.add(aboveTopButton);
    frame.setSize(300, 200);/*from   w w w .  ja v a  2  s. c  om*/
    frame.setVisible(true);
}

From source file:Main.java

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

    // Add a close button
    JButton closeButton = new JButton("Close");
    Container contentPane = frame.getContentPane();
    contentPane.add(closeButton);

    // Calculates and sets appropriate size for the frame
    frame.pack();/*from w w  w. j  a v  a 2 s. c  o  m*/

    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("LabelFor Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel("Username");
    JTextField textField = new JTextField();
    label.setDisplayedMnemonic(KeyEvent.VK_U);
    label.setLabelFor(textField);//from   w ww  . j  a v  a 2s  .c om
    Container box = Box.createHorizontalBox();
    box.add(label);
    box.add(textField);
    frame.add(box, BorderLayout.NORTH);
    frame.add(new JButton("Submit"), BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

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

    Border loweredBorder = BorderFactory.createLoweredSoftBevelBorder();
    JButton loweredButton = new JButton("Lowered");
    loweredButton.setBorder(loweredBorder);

    Container contentPane = frame.getContentPane();
    contentPane.add(loweredButton);
    frame.setSize(300, 200);/*w w  w  . ja  va2  s.  c  om*/
    frame.setVisible(true);

}

From source file:MainClass.java

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

    Border raisedBorder = BorderFactory.createRaisedBevelBorder();
    JButton raisedButton = new JButton("Raised");
    raisedButton.setBorder(raisedBorder);

    Container contentPane = frame.getContentPane();
    contentPane.add(raisedButton);
    frame.setSize(300, 200);//from w ww.  ja  v  a  2  s.  co m
    frame.setVisible(true);

}

From source file:MainClass.java

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

    TitledBorder belowBottomBorder = BorderFactory.createTitledBorder("BelowBottom");
    belowBottomBorder.setTitlePosition(TitledBorder.BELOW_BOTTOM);
    JButton belowBottomButton = new JButton();
    belowBottomButton.setBorder(belowBottomBorder);

    Container contentPane = frame.getContentPane();
    contentPane.add(belowBottomButton);
    frame.setSize(300, 200);/*w ww.jav a2  s. c om*/
    frame.setVisible(true);
}

From source file:Main.java

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

    Border raisedBorder = BorderFactory.createRaisedSoftBevelBorder();
    JButton raisedButton = new JButton("Raised");
    raisedButton.setBorder(raisedBorder);

    Container contentPane = frame.getContentPane();
    contentPane.add(raisedButton);
    frame.setSize(300, 200);/*from   w w  w. j a va 2  s .  c om*/
    frame.setVisible(true);

}