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[] a) {
    JFrame frame = new JFrame("Etched Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED);
    Border loweredBorder = new EtchedBorder(EtchedBorder.LOWERED);
    JButton raisedButton = new JButton("Raised");
    raisedButton.setBorder(raisedBorder);
    JButton loweredButton = new JButton("Lowered");
    loweredButton.setBorder(loweredBorder);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2, 5, 5));
    contentPane.add(raisedButton);
    contentPane.add(loweredButton);//  w ww  .j  av  a2  s  .  c  om
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:CloseAction.java

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

    JButton closeButton = new JButton(new CloseAction());
    contentPane.add(closeButton);

    frame.pack();//from  w  ww  .j a  va 2 s . co m
    frame.setVisible(true);
}

From source file:AnEtchedBorder.java

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

    Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED);
    Border loweredBorder = new EtchedBorder(EtchedBorder.LOWERED);
    JButton raisedButton = new JButton("Raised");
    raisedButton.setBorder(raisedBorder);

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

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2, 5, 5));
    contentPane.add(raisedButton);
    contentPane.add(loweredButton);//from  w  w  w  . j a va 2s.c  o  m
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:MetalModExample.java

public static void main(String[] args) {
    try {//  ww w .ja  va 2  s  .c  om
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception e) {
        System.err.println("Metal is not available on this platform?!");
        System.exit(1);
    }
    JComponent before = makeExamplePane();

    UIManager.put("ScrollBarUI", "MyMetalScrollBarUI");

    JComponent after = makeExamplePane();

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

    Container c = f.getContentPane();
    c.setLayout(new GridLayout(2, 1, 0, 1));
    c.add(before);
    c.add(after);
    f.setSize(450, 400);
    f.setVisible(true);
}

From source file:Main.java

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

    JButton closeButton = new JButton("Close");
    contentPane.add(closeButton);

    closeButton.addActionListener(e -> System.exit(0));
    // Add a MouseListener to the JButton
    closeButton.addMouseListener(new MouseAdapter() {
        @Override//from w ww .  j a  v a  2  s  . c om
        public void mouseEntered(MouseEvent e) {
            closeButton.setText("Mouse has  entered!");
        }

        @Override
        public void mouseExited(MouseEvent e) {
            closeButton.setText("Mouse has  exited!");
        }
    });
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] av) {
    JFrame frame = new JFrame();
    Container cp = frame.getContentPane();
    cp.add(new Main(new File(".")));
    frame.pack();/*from  w  w w.ja v  a2s.c o  m*/
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:YAxisAlignX.java

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

    Container panel1 = makeIt("Left", Component.LEFT_ALIGNMENT);
    Container panel2 = makeIt("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("Right", Component.RIGHT_ALIGNMENT);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(panel1);
    contentPane.add(panel2);//from w  ww . ja  v a 2  s . c  o  m
    contentPane.add(panel3);

    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) throws Exception {
    JFrame jf = new JFrame("Demo");
    Container cp = jf.getContentPane();
    TextFormat tl = new TextFormat();
    cp.add(tl);
    jf.setSize(300, 200);/*  w w w .  ja  v  a2  s .  c o m*/
    jf.setVisible(true);
}

From source file:ATitledBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Titled Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border thisBorder = BorderFactory.createTitledBorder("Easy");
    Icon thatIcon = new ImageIcon("diamond.gif");
    Border thatBorder1 = new MatteBorder(18, 20, 18, 20, thatIcon);
    Border thatBorder2 = new TitledBorder(thatBorder1, "Harder");
    Font font = new Font("Serif", Font.ITALIC, 12);
    Border thatBorder = new TitledBorder(thatBorder2, "Harder", TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM,
            font, Color.red);//  www .  ja va 2  s. c  o m
    JButton thisButton = new JButton("Easy");
    thisButton.setBorder(thisBorder);
    JButton thatButton = new JButton("Harder");
    thatButton.setBorder(thatBorder);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2));
    contentPane.add(thisButton);
    contentPane.add(thatButton);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(5, 5));

    int sz = 4;//from w  w  w  . j av a2 s . c o m
    Container content = new JPanel(new GridLayout(sz, 0, 2, 2));
    for (int f = 0; f < sz * sz; f++) {
        content.add(new JButton());
    }
    gui.add(content, BorderLayout.CENTER);

    Container info = new JPanel(new FlowLayout(FlowLayout.CENTER, 50, 5));
    info.add(new JLabel("Flow"));
    info.add(new JLabel("Layout"));
    gui.add(info, BorderLayout.PAGE_START);

    gui.add(new JLabel("Label"), BorderLayout.LINE_END);

    JOptionPane.showMessageDialog(null, gui);
}