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[] argv) throws Exception {

    JFrame container = new JFrame();
    // Get number of children
    int count = container.getComponentCount();

    for (int i = 0; i < count; i++) {
        Component c = container.getComponent(i);
    }//  w  w w.  ja va 2  s  .  c o m
}

From source file:OptionDialog.java

public static void main(String argv[]) {
    if (JOptionPane.showConfirmDialog(new JFrame(), "Do you want to quit this application ?", "Title",
            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
        System.exit(0);//from www . j a v a 2  s  . co m

}

From source file:AddingItemToComboBox.java

License:asdf

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

    JComboBox jComboBox1 = new JComboBox();
    jComboBox1.addItem("asdf");
    Object cmboitem = jComboBox1.getSelectedItem();
    System.out.println(cmboitem);

    frame.add(jComboBox1);/*from w  w  w .j a  v a2s  . com*/

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

From source file:MesageDialogWithStringArray.java

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

    String multiLineMsg[] = { "Hello,", "World" };
    JOptionPane.showMessageDialog(parent, multiLineMsg);
}

From source file:Main.java

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

    JPanel centeredPanel = new JPanel();
    centeredPanel.add(new JButton("one"));
    centeredPanel.add(new JButton("two"));

    f.getContentPane().add(centeredPanel);
    f.pack();/*from   w ww .  j a v  a  2  s  . c o m*/
    f.setVisible(true);
}

From source file:BigValueJOptionpaneDialog.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    String bigList[] = new String[30];

    for (int i = 0; i < bigList.length; i++) {
        bigList[i] = Integer.toString(i);
    }/*from   ww w . j a v a  2s  .  c o m*/

    JOptionPane.showInputDialog(frame, "Pick a printer", "Input", JOptionPane.QUESTION_MESSAGE, null, bigList,
            "Titan");

}

From source file:Main.java

public static void main(String args[]) {
    int n = JOptionPane.showOptionDialog(new JFrame(), "Message", "Title", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Yes", "No" }, JOptionPane.YES_OPTION);

    if (n == JOptionPane.YES_OPTION) {
        System.out.println("Yes");
    } else if (n == JOptionPane.NO_OPTION) {
        System.out.println("No");
    } else if (n == JOptionPane.CLOSED_OPTION) {
        System.out.println("Closed by hitting the cross");
    }/*from www  .ja va  2 s.  c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());
    JLabel label = new JLabel("<html>" + "<img src=\"" + Main.class.getResource("/resource/path/to/image1.jpg")
            + "\">" + "<img src=\"" + Main.class.getResource("/resource/path/to/image2.jpg") + "\">"
            + "The text</html>");
    frame.add(label, BorderLayout.CENTER);
    frame.setBounds(100, 100, 200, 100);
    frame.setVisible(true);//from w w w  .j  av a  2 s .c  om
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JButton button = new JButton("Click me");
    button.addActionListener(e -> JOptionPane.showMessageDialog(frame, "Hello World!"));
    frame.getContentPane().add(button);//  w w w. j  ava2  s .  co  m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTree tree = new JTree();
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);//from   w  ww . j ava  2s  . c  o  m
    }
    f.add(new JScrollPane(tree));
    f.pack();
    f.setSize(200, 200);
    f.setVisible(true);
}