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... args) {
    JFrame f = new JFrame();
    JButton button;//from   w  w w  . j a  va 2 s. c  o  m

    JPanel p = new JPanel();
    button = new JButton("Button");
    p.setLayout(null);
    button.setBounds(40, 100, 100, 60);
    p.add(button);

    f.add(p);
    // setLayout(null);
    f.setDefaultCloseOperation(3);
    f.setSize(400, 400);
    f.setVisible(true);
}

From source file:SimpleBorder.java

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

    JButton button = new JButton("Aaaaaaaaaaa");
    button.setBorder(new SimpleBorder());
    frame.add(button);
    frame.pack();/*w ww . java2 s  .co m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Selecting JList");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JList jlist = new JList(labels);
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1);

    ListSelectionListener listSelectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            System.out.println(jlist.getSelectedValue());
        }//from   www.j av a2  s.  co  m
    };
    jlist.addListSelectionListener(listSelectionListener);

    frame.setSize(350, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Selecting JList");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JList jlist = new JList(labels);
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1);

    ListSelectionListener listSelectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            Object[] objs = jlist.getSelectedValues();
        }//from   w  ww.j a  v a 2 s.  c  om
    };
    jlist.addListSelectionListener(listSelectionListener);

    frame.setSize(350, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Selecting JList");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JList jlist = new JList(labels);
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1);

    ListSelectionListener listSelectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            System.out.println(jlist.getSelectedIndex());
        }/*  w  w w . j a v  a  2 s. c  o m*/
    };
    jlist.addListSelectionListener(listSelectionListener);

    frame.setSize(350, 200);
    frame.setVisible(true);
}

From source file:Absolute.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setLayout(null);/*from w  w w.java2s . c  om*/

    JButton ok = new JButton("OK");
    ok.setBounds(50, 150, 80, 25);

    JButton close = new JButton("Close");
    close.setBounds(150, 150, 80, 25);

    f.add(ok);
    f.add(close);

    f.setSize(300, 250);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Selecting JList");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JList jlist = new JList(labels);
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1);

    ListSelectionListener listSelectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            List objs = jlist.getSelectedValuesList();
        }/*from ww  w  . jav  a 2  s  .co m*/
    };
    jlist.addListSelectionListener(listSelectionListener);

    frame.setSize(350, 200);
    frame.setVisible(true);
}

From source file:MyCellRenderer.java

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

    JList list = new JList(new String[] { "A", "B", "C" });
    list.setCellRenderer(new MyCellRenderer());
    frame.add(new JScrollPane(list));

    frame.setSize(300, 200);//from w  w w.java  2s  .c o m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        @Override//  www . j a  v  a  2  s.c  o  m
        public void run() {
            try {
                Image img = null;
                img = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));

                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                frame.add(new ImagePanel(img));
                frame.pack();
                frame.setVisible(true);
            } catch (Exception exp) {
                exp.printStackTrace();
            }
        }
    });
}

From source file:CustomListener.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Popup JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label = new JLabel();

    label.addMouseMotionListener(new CustomListener() {
    });/*  ww  w . j a  va  2  s . c om*/

    frame.add(label);
    frame.setSize(300, 200);
    frame.setVisible(true);
}