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

public static void main(String args[]) {
    JFrame f = new JFrame("JToggleButton Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    content.add(new JToggleButton("North"), BorderLayout.NORTH);
    content.add(new JToggleButton("East"), BorderLayout.EAST);
    content.add(new JToggleButton("West"), BorderLayout.WEST);
    content.add(new JToggleButton("Center"), BorderLayout.CENTER);
    content.add(new JToggleButton("South"), BorderLayout.SOUTH);
    f.setSize(300, 200);/*w w w  .  j  a  va2s.c o  m*/
    f.setVisible(true);
}

From source file:ScrollBarPieces.java

public static void main(String args[]) {
    JScrollBar oneJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    String title = (args.length == 0 ? "ScrollBar Sample" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = frame.getContentPane();
    contentPane.add(oneJScrollBar, BorderLayout.NORTH);
    frame.setSize(200, 44);//  ww  w  .  j a  va  2 s.c  om
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Color Matted Border");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border solidBorder = new MatteBorder(10, 5, 2, 20, Color.RED);
    JButton solidButton = new JButton("10x5x2x20");
    solidButton.setBorder(solidBorder);//from   w w w.ja v a  2  s  .c om
    Container contentPane = frame.getContentPane();
    contentPane.add(solidButton, BorderLayout.CENTER);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:ListSample.java

public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };

    String title = "JList Sample";
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList list = new JList(labels);
    JScrollPane scrollPane = new JScrollPane(list);

    Container contentPane = f.getContentPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);

    f.setSize(200, 200);/*from   www. ja  v a2  s . c om*/
    f.setVisible(true);
}

From source file:AnEmptyBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Empty Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0);
    JButton emptyButton = new JButton("With Empty");
    emptyButton.setBorder(emptyBorder);//  www .j  a  v a  2s. c  om
    JButton nonemptyButton = new JButton("Without Empty");
    Container contentPane = frame.getContentPane();
    contentPane.add(emptyButton, BorderLayout.NORTH);
    contentPane.add(nonemptyButton, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:DoubleTitle.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Double Title");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
    topBorder.setTitlePosition(TitledBorder.TOP);
    TitledBorder doubleBorder = new TitledBorder(topBorder, "Bottom", TitledBorder.RIGHT, TitledBorder.BOTTOM);
    JButton doubleButton = new JButton();
    doubleButton.setBorder(doubleBorder);
    Container contentPane = frame.getContentPane();
    contentPane.add(doubleButton, BorderLayout.CENTER);
    frame.setSize(300, 100);//from  w w w.j a v a2s . c o m
    frame.setVisible(true);
}

From source file:ButtonModelTesting.java

public static void main(String args[]) {
    JFrame f = new JFrame("Button Model Tester");
    JButton jb1 = new JButton("Hello");
    ButtonModel bm = jb1.getModel();
    JButton jb2 = new JButton("World");
    jb2.setModel(bm);/*from ww  w . j  a  va 2 s.  c om*/
    Container c = f.getContentPane();
    c.add(jb1, BorderLayout.NORTH);
    c.add(jb2, BorderLayout.SOUTH);
    jb1.addActionListener(new MessageActionListener("Selected One"));
    jb2.addActionListener(new MessageActionListener("Selected Two"));
    f.pack();
    f.show();
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    JButton jb1 = new JButton("Hello");
    ButtonModel bm = jb1.getModel();
    JButton jb2 = new JButton("World");
    jb2.setModel(bm);// w  w w  .j av a2s. co  m
    Container c = f.getContentPane();
    c.add(jb1, BorderLayout.NORTH);
    c.add(jb2, BorderLayout.SOUTH);
    jb1.addActionListener(new MessageActionListener("Selected One"));
    jb2.addActionListener(new MessageActionListener("Selected Two"));
    f.pack();
    f.show();
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Empty Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0);
    JButton emptyButton = new JButton("With Empty");
    emptyButton.setBorder(emptyBorder);//from w  w  w  .  ja  v  a  2 s. co  m
    JButton nonemptyButton = new JButton("Without Empty");
    Container contentPane = frame.getContentPane();
    contentPane.add(emptyButton, BorderLayout.NORTH);
    contentPane.add(nonemptyButton, BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:MainClass.java

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

    Border roundedBorder = new LineBorder(Color.BLACK, 12, true);

    JButton roundedButton = new JButton("Rounded 12 Pixel");
    roundedButton.setBorder(roundedBorder);

    Container contentPane = frame.getContentPane();
    contentPane.add(roundedButton, BorderLayout.SOUTH);
    frame.pack();//w w w.ja  v  a  2s  .co m
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}