kmil
kmil

Reputation: 243

How do I get JFrame to display my GUI?

I am using Netbeans and have previously had this up and running but I messed with some of the code and now it isnt.. Could somebody please tell me what I am doing wrong?

public class OrderGUI extends javax.swing.JFrame {

ArrayList orders = new ArrayList<>();

public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(OrderGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(OrderGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(OrderGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(OrderGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            OrderGUI gui = new OrderGUI();
            gui.setVisible(true);
            gui.setTitle("Flexbox Order System");
            gui.setResizable(false);
            gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    });
}
}

Upvotes: 0

Views: 551

Answers (1)

wax_lyrical
wax_lyrical

Reputation: 942

You just forgot to set the size: it's working fine on my system. Here, I cleaned up a bit for you.

 package developerToolsNotForDeployment;

 import javax.swing.*;
 import java.awt.*;
 import java.util.ArrayList;


 public class OrderGUI extends javax.swing.JFrame {

 ArrayList orders = new ArrayList<>();

 public static void main(String args[]) {
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

/* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            OrderGUI gui = new OrderGUI();
            gui.setTitle("Flexbox Order System");
            gui.setResizable(false);
            gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            gui.setSize(new Dimension(400,400));
            gui.setVisible(true);
        }
    });
}

Upvotes: 2

Related Questions