JFormDesigner in IntelliJ will not display GUI when run

1.7k Views Asked by At

I can't get my GUI to display in my program. I am using JFormDesigner in IntelliJ IDE and cannot get it to work. It runs successfully but the GUI form does not come up at all. Here is my code, feel like I am missing something simple:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.miginfocom.swing.*;
/*
 * Created by JFormDesigner on Thu Apr 12 15:41:25 SAST 2018
 */



/**
 * @author Jordan
 */
public class hashTable extends JPanel {
    public hashTable() {
        initComponents();
    }

    public static void main(String [] args) {
        hashTable ht = new hashTable();
        ht.setVisible(true);
    }

    private void button1ActionPerformed(ActionEvent e) {

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - Jordan Taschner
        label2 = new JLabel();
        label3 = new JLabel();
        textField1 = new JTextField();
        button1 = new JButton();
        textField2 = new JTextField();

        //======== this ========

        // JFormDesigner evaluation mark
        setBorder(new javax.swing.border.CompoundBorder(
            new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
                "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
                javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
                java.awt.Color.red), getBorder())); addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

        setLayout(new MigLayout(
            "hidemode 3",
            // columns
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]" +
            "[fill]",
            // rows
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]" +
            "[]"));

        //---- label2 ----
        label2.setText("VOTER APPLICATION");
        label2.setFont(label2.getFont().deriveFont(Font.BOLD, label2.getFont().getSize() + 3f));
        add(label2, "cell 3 0 7 1");

        //---- label3 ----
        label3.setText("CSC2 Assignment 3");
        label3.setForeground(new Color(229, 218, 218));
        label3.setFont(new Font("Menlo", Font.ITALIC, 13));
        add(label3, "cell 4 1");

        //---- textField1 ----
        textField1.setText("(enter ID number)");
        textField1.setFont(textField1.getFont().deriveFont(textField1.getFont().getStyle() | Font.ITALIC));
        add(textField1, "cell 4 4 2 1");

        //---- button1 ----
        button1.setText("Find Name");
        button1.setFont(new Font("Menlo", Font.PLAIN, 13));
        button1.addActionListener(e -> button1ActionPerformed(e));
        add(button1, "cell 4 6");
        add(textField2, "cell 4 7 2 1");
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - Jordan Taschner
    private JLabel label2;
    private JLabel label3;
    private JTextField textField1;
    private JButton button1;
    private JTextField textField2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}

Any help would be appreciated. I am thinking there is a problem with setting it to visible or packing it. I am new to java so I am not too sure.

1

There are 1 best solutions below

1
yole On

You can't just show a JPanel; you need to create a JFrame and use setContentPane() to show the panel inside the JFrame:

JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new hashTable());
frame.pack();
frame.setVisible(true);