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: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" }, "McDonalds");
            System.out.println("Response: " + response);
        }//from   ww  w.  j  a v  a 2 s.  c  o  m
    };
    button.addActionListener(actionListener);
    Container contentPane = frame.getContentPane();
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Background Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final ImageIcon imageIcon = new ImageIcon("draft.gif");
    JTextArea textArea = new JTextArea() {
        Image image = imageIcon.getImage();

        Image grayImage = GrayFilter.createDisabledImage(image);
        {//from w ww .  j  a  v  a 2 s .c om
            setOpaque(false);
        }

        public void paint(Graphics g) {
            g.drawImage(grayImage, 0, 0, this);
            super.paint(g);
        }
    };
    JScrollPane scrollPane = new JScrollPane(textArea);
    Container content = frame.getContentPane();
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(250, 250);
    frame.setVisible(true);
}

From source file:ToolBarSample.java

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

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);//from www  .  j  a  va 2 s  . com

    JButton button = new JButton("button");
    toolbar.add(button);
    toolbar.addSeparator();

    toolbar.add(new JButton("button 2"));

    toolbar.add(new JComboBox(new String[] { "A", "B", "C" }));

    Container contentPane = frame.getContentPane();
    contentPane.add(toolbar, BorderLayout.NORTH);
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(350, 150);
    frame.setVisible(true);
}

From source file:TickSliders.java

public static void main(String args[]) {
    JFrame f = new JFrame("Tick Slider");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // No Ticks/*from  w  w  w  . j  av a 2 s  . com*/
    JSlider jSliderOne = new JSlider();
    // Major Tick 25 - Minor 5
    JSlider jSliderTwo = new JSlider();
    jSliderTwo.setMinorTickSpacing(5);
    jSliderTwo.setMajorTickSpacing(25);
    jSliderTwo.setPaintTicks(true);
    jSliderTwo.setSnapToTicks(true);
    // Major Tick 25 - Minor 6
    JSlider jSliderThree = new JSlider(JSlider.VERTICAL);
    jSliderThree.setMinorTickSpacing(6);
    jSliderThree.setMajorTickSpacing(25);
    jSliderThree.setPaintTicks(true);
    JSlider jSliderFour = new JSlider(JSlider.VERTICAL);
    // Major Tick 25 - Minor 1
    jSliderFour.setMinorTickSpacing(1);
    jSliderFour.setMajorTickSpacing(25);
    jSliderFour.setPaintTicks(true);

    Container c = f.getContentPane();
    c.add(jSliderOne, BorderLayout.NORTH);
    c.add(jSliderTwo, BorderLayout.SOUTH);
    c.add(jSliderThree, BorderLayout.WEST);
    c.add(jSliderFour, BorderLayout.EAST);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:LazySample.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Lazy Example");

    Object iconObject = LookAndFeel.makeIcon(LazySample.class, "World.gif");
    UIManager.put("Tree.leafIcon", iconObject);

    Integer fifteen = new Integer(15);
    Object lazyArgs[] = new Object[] { Color.green, Boolean.TRUE, fifteen, fifteen };
    Object lazyDiamond = new UIDefaults.ProxyLazyValue("DiamondIcon", lazyArgs);
    UIManager.put("Tree.openIcon", lazyDiamond);

    JTree tree = new JTree();
    JScrollPane scrollPane = new JScrollPane(tree);

    Container contentPane = frame.getContentPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(200, 200);/* w  ww  .j av  a  2s . c  om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "CheckBox Sample" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Pizza Toppings");
    panel.setBorder(border);/*from  www. j  av a  2s  .  co m*/
    JCheckBox check = new JCheckBox("Anchovies");
    panel.add(check);
    check = new JCheckBox("Garlic");
    panel.add(check);
    check = new JCheckBox("Onions");
    panel.add(check);
    check = new JCheckBox("Pepperoni");
    panel.add(check);
    check = new JCheckBox("Spinach");
    panel.add(check);
    JButton button = new JButton("Submit");
    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.CENTER);
    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, 2, true);

    JButton thinButton = new JButton("1 Pixel");
    thinButton.setBorder(thinBorder);/*from  www  . j  a  v a2s. co m*/

    JButton thickButton = new JButton("12 Pixel");
    thickButton.setBorder(thickBorder);

    JButton roundedButton = new JButton("Rounded 2 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:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Active Example");
    UIManager.put("LabelFactory", new ActiveLabel());
    final JPanel panel = new JPanel();
    JButton button = new JButton("Get");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JLabel label = (JLabel) UIManager.get("LabelFactory");
            panel.add(label);//w  ww.j  a v a2s.c o m
            panel.revalidate();
        }
    };
    button.addActionListener(actionListener);

    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(200, 200);
    frame.setVisible(true);
}

From source file:FlatCheckBox.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Flat CheckBox Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Pizza Toppings");
    panel.setBorder(border);/*from   w  ww .j a  v a  2 s  .  c  om*/
    JCheckBox check = new JCheckBox("Anchovies");
    check.setBorderPaintedFlat(true);
    panel.add(check);
    check = new JCheckBox("Garlic");
    panel.add(check);
    check = new JCheckBox("Onions");
    check.setBorderPaintedFlat(true);
    panel.add(check);
    check = new JCheckBox("Pepperoni");
    panel.add(check);
    check = new JCheckBox("Spinach");
    check.setBorderPaintedFlat(true);
    panel.add(check);
    JButton button = new JButton("Submit");
    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ArrayListComboBoxModel.java

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

    Collection col = System.getProperties().values();
    ArrayList arrayList = new ArrayList(col);
    ArrayListComboBoxModel model = new ArrayListComboBoxModel(arrayList);

    JComboBox comboBox = new JComboBox(model);

    Container contentPane = frame.getContentPane();
    contentPane.add(comboBox, BorderLayout.NORTH);
    frame.setSize(300, 225);//from  ww w .j a  v  a  2s  .  com
    frame.setVisible(true);
}