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

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

    Border thickBorder = new LineBorder(Color.WHITE, 12);

    JButton thickButton = new JButton("12 Pixel");
    thickButton.setBorder(thickBorder);/*from  www  .  ja v  a  2 s  .  co m*/

    Container contentPane = frame.getContentPane();
    contentPane.add(thickButton, BorderLayout.NORTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:DualSample.java

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

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

    JComboBox comboBox = new JComboBox(labels);
    comboBox.setMaximumRowCount(4);// w w w.  j av  a  2  s. c  o m

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

    f.setSize(300, 200);
    f.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 thinBorder = LineBorder.createBlackLineBorder();

    JButton thinButton = new JButton("1 Pixel");
    thinButton.setBorder(thinBorder);//w ww  .  j a va 2  s  .  c  om

    Container contentPane = frame.getContentPane();
    contentPane.add(thinButton, BorderLayout.NORTH);
    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("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   ww w.  j  a  v  a 2  s . c o m
    frame.setVisible(true);
}

From source file:ScrollSlider.java

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

    JSlider aJSlider = new JSlider(JSlider.HORIZONTAL, 0, 1000, 500);
    ChangeListener aChangeListener = new BoundedChangeListener();
    aJSlider.addChangeListener(aChangeListener);
    Container c = f.getContentPane();
    c.add(aJSlider, BorderLayout.SOUTH);
    f.setSize(300, 200);// ww  w. j  a  va  2s  .  co  m
    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);/* ww  w .j  a va2  s . c om*/

    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: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  av a  2s.c om
    frame.setVisible(true);
}

From source file:NoButtonPopup.java

public static void main(String args[]) {

    JFrame frame = new JFrame("NoButton Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Ask");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component source = (Component) actionEvent.getSource();
            int response = JOptionPane.showOptionDialog(source, "", "Empty?", JOptionPane.DEFAULT_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, new Object[] {}, null);
            System.out.println("Response: " + response);
        }/*from  w w w  .  j av a 2s . c om*/
    };
    button.addActionListener(actionListener);
    Container contentPane = frame.getContentPane();
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ALineBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Line Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border thinBorder = LineBorder.createBlackLineBorder();
    Border thickBorder = new LineBorder(Color.white, 12);
    Border roundedBorder = new LineBorder(Color.black, 12, true);
    JButton thinButton = new JButton("1 Pixel");
    thinButton.setBorder(thinBorder);//w  w w . j a va  2 s . c o  m
    JButton thickButton = new JButton("12 Pixel");
    thickButton.setBorder(thickBorder);
    JButton roundedButton = new JButton("Rounded 12 Pixel");
    roundedButton.setBorder(roundedBorder);
    Container contentPane = frame.getContentPane();
    contentPane.add(thinButton, BorderLayout.NORTH);
    contentPane.add(thickButton, BorderLayout.CENTER);
    contentPane.add(roundedButton, BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:SamplePopup.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Sample Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Ask");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component source = (Component) actionEvent.getSource();
            Object response = JOptionPane.showInputDialog(source, "Where would you like to go to lunch?",
                    "Select a Destination", JOptionPane.QUESTION_MESSAGE, null,
                    new String[] { "A", "B", "C", "D", "E" }, "B");
            System.out.println("Response: " + response);
        }//from  ww w .j av  a  2s .c  o  m
    };
    button.addActionListener(actionListener);
    Container contentPane = frame.getContentPane();
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}