Example usage for javax.swing JFrame add

List of usage examples for javax.swing JFrame add

Introduction

In this page you can find the example usage for javax.swing JFrame add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextField component = new JTextField();
    component.addKeyListener(new MyKeyListener());

    JFrame f = new JFrame();

    f.add(component);
    f.setSize(300, 300);//from  w ww.j a va 2  s.c  o m
    f.setVisible(true);

}

From source file:FlowLayoutExample.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    JTextArea area = new JTextArea("text area");
    area.setPreferredSize(new Dimension(100, 100));

    JButton button = new JButton("button");
    panel.add(button);/*ww  w  .jav  a2 s  . c  o  m*/

    panel.add(new JScrollPane(area));

    JFrame f = new JFrame();
    f.add(panel);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JTextField component = new JTextField();
    component.addMouseListener(new MyMouseListener());
    JFrame f = new JFrame();

    f.add(component);
    f.setSize(300, 300);/*  ww w .jav  a2s. co m*/
    f.setVisible(true);

    component.addMouseListener(new MyMouseListener());
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.add(new Main());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationByPlatform(true);// w w w.  j  a  v a2  s  .  c om
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JWindow window = new JWindow();
    window.getContentPane().add(new JLabel("Loading", SwingConstants.CENTER));
    window.setBounds(500, 150, 300, 200);
    window.setVisible(true);//from  ww w.  j  a  v  a2 s .  c o m
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
    window.setVisible(false);
    JFrame frame = new JFrame();
    frame.add(new JLabel("Welcome Swing application..."));
    frame.setVisible(true);
    frame.setSize(300, 200);
    window.dispose();
}

From source file:BorderExample.java

public static void main(String[] args) {
    JPanel panel = new JPanel(new BorderLayout());
    JPanel top = new JPanel();

    top.setBackground(Color.gray);
    top.setPreferredSize(new Dimension(250, 150));
    panel.add(top);//w w  w.  j a  v a2s . c  om

    panel.setBorder(new EmptyBorder(new Insets(10, 20, 30, 40)));
    JFrame f = new JFrame();
    f.add(panel);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Icon leafIcon = new ImageIcon("leaf.gif");
    Icon openIcon = new ImageIcon("open.gif");
    Icon closedIcon = new ImageIcon("closed.gif");

    JTree tree = new JTree();
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
    renderer.setLeafIcon(leafIcon);//  w  w  w  . j  a  v  a 2  s. co m
    renderer.setClosedIcon(closedIcon);
    renderer.setOpenIcon(openIcon);

    JFrame f = new JFrame();
    f.add(new JScrollPane(tree));
    f.setSize(300, 300);
    f.setVisible(true);

}

From source file:ShadowText.java

public static void main(String[] args) throws IOException {
    JFrame f = new JFrame();
    f.add(new ShadowText());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(450, 150);/*from   ww  w  .ja  v  a  2s .co m*/

    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JTextField component = new JTextField();
    component.addMouseListener(new MyMouseListener());
    JFrame f = new JFrame();

    f.add(component);
    f.setSize(300, 300);// w  w w .j a v  a  2 s  .  c o  m
    f.setVisible(true);

}

From source file:GrayImage.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.add(new GrayImage());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);/* w  w  w  .  j a v  a  2 s  .  co m*/
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}