Example usage for javax.swing JFrame JFrame

List of usage examples for javax.swing JFrame JFrame

Introduction

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

Prototype

public JFrame() throws HeadlessException 

Source Link

Document

Constructs a new frame that is initially invisible.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.add(new JMenuItem("One"));
    popupMenu.add(new JMenuItem("Two"));
    popupMenu.add(new JMenuItem("Three"));
    JList<String> list = new JList<>(
            new String[] { "Hello", "World", "Something", "Else", "Out", "Of", "Ideas" });
    list.setComponentPopupMenu(popupMenu);
    f.add(list);/*  w  w  w .  j  av  a  2  s . c  o  m*/
    f.pack();
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector<String> data = new Vector<String>();
    for (int i = 1; i < 100; i++) {
        data.add("Entry " + i);
    }/*from w  w  w . j av a  2s.  c o  m*/
    JList<String> list = new JList<>(data);
    list.setVisibleRowCount(8);
    JScrollPane scrollPane = new JScrollPane(list);
    frame.add(scrollPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String argv[]) {
    String message = "line\n" + "line 2\n" + "line 3";
    JOptionPane.showMessageDialog(new JFrame(), message, "Dialog", JOptionPane.ERROR_MESSAGE);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String[] selections = { "green", "red", "orange", "dark blue" };
    JList list = new JList(selections);
    list.setSelectedIndex(1);/*w w w .  j  a  va2  s . com*/
    System.out.println(list.getSelectedValue());
    frame.add(new JScrollPane(list));
    frame.pack();

    frame.setVisible(true);
}

From source file:Main.java

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

    Vector months = new Vector();
    JList list = new JList(months);

    months.addElement("January");
    months.addElement("December");

    frame.add(new JScrollPane(list));

    frame.setSize(300, 200);/*from   ww  w.j  a v a2  s.  c  o m*/
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel panel = (JPanel) frame.getContentPane();
    panel.setLayout(null);/*  w w w .ja v a2 s .c  o m*/

    JLabel label = new JLabel("aaa");
    panel.add(label);
    Dimension size = label.getPreferredSize();
    label.setBounds(100, 100, size.width, size.height);

    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    MyTextPane textPane = new MyTextPane();
    frame.add(textPane);//from   w  ww  .  j  a v a2s  .c  o m

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

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    Box b = Box.createVerticalBox();

    JTextField field1 = new JTextField();
    JTextField field2 = new JTextField();
    field1.setMaximumSize(new Dimension(Integer.MAX_VALUE, field1.getPreferredSize().height));
    field2.setMaximumSize(new Dimension(Integer.MAX_VALUE, field2.getPreferredSize().height));
    b.add(field1);/* w  w w  .jav  a 2  s . c  om*/
    b.add(field2);

    b.add(Box.createVerticalGlue());

    f.setContentPane(b);
    f.setSize(500, 200);
    f.setVisible(true);
}

From source file:InputDialog.java

public static void main(String argv[]) {
    String input = (String) JOptionPane.showInputDialog(new JFrame(),
            "Please enter your favorite Shakespeare play", "Title", JOptionPane.INFORMATION_MESSAGE,
            new ImageIcon("java2sLogo.GIF"), null, "Romeo and Juliet");
    System.out.println("User's input: " + input);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    Integer[][] board = { { 1, 1, 1, 1, 2, 0, 0, 0, 0 }, { 0, 0, 5, 0, 1, 0, 0, 2, 4 },
            { 1, 0, 0, 4, 0, 0, 0, 3, 8 }, { 0, 0, 0, 6, 1, 0, 0, 3, 7 }, { 0, 0, 4, 5, 3, 8, 9, 4, 0 },
            { 8, 0, 0, 0, 1, 7, 0, 4, 0 }, { 7, 4, 0, 0, 1, 6, 0, 3, 1 }, { 6, 1, 0, 0, 1, 0, 3, 3, 0 },
            { 0, 0, 0, 0, 1, 1, 1, 1, 0 } };

    String col[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
    JTable table = new JTable(board, col);
    panel.add(table, BorderLayout.CENTER);

    frame.add(panel);//  w w  w.  ja v  a 2 s  .c  o  m
    frame.setSize(800, 500);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}