java - JformDesigner-Eclipse Main 将无法运行

标签 java eclipse eclipse-plugin jform-designer

所以我确实浏览并看到了一些与我类似的问题,但对它们有效的修复仍然无法为我显示窗口。我正在尝试创建一个登录屏幕,这是生成的代码,我复制了之前问题中的 public static main,但它仍然只显示一个最小尺寸的窗口,其中没有任何内容:

package surveyducky;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import com.jgoodies.forms.factories.*;

public class LoginForm extends JFrame{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    public LoginForm() {
        initComponents();
        pack();
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                 LoginForm GUI = new LoginForm();
                 GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 GUI.setVisible(true);
            }
        });
    }
    private void submitActionPerformed(ActionEvent e) {
        // TODO add your code here
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - Tamara Turton
        DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
        LoginJ = new JPanel();
        panel1 = new JPanel();
        titel = compFactory.createTitle("Welcome to Survey Ducky!");
        userlabel = new JLabel();
        email = new JTextField();
        passlabel = new JLabel();
        password = new JPasswordField();
        vSpacer1 = new JPanel(null);
        submit = new JButton();
        forgotpass = new JButton();
        createacc = new JButton();

        //======== LoginJ ========
        {   
            // JFormDesigner evaluation mark
            LoginJ.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), LoginJ.getBorder())); LoginJ.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

            LoginJ.setLayout(new GridBagLayout());
            ((GridBagLayout)LoginJ.getLayout()).columnWidths = new int[] {0, 163};
            ((GridBagLayout)LoginJ.getLayout()).rowHeights = new int[] {50, 43, 27, 47, 25, 0, 54, 0, 0, 0};
            ((GridBagLayout)LoginJ.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

            //======== panel1 ========
            {
                panel1.setLayout(new GridBagLayout());
                ((GridBagLayout)panel1.getLayout()).columnWidths = new int[] {353};
                ((GridBagLayout)panel1.getLayout()).rowHeights = new int[] {0, 0, 0};
                ((GridBagLayout)panel1.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0E-4};

                //---- titel ----
                titel.setFont(new Font("Brush Script MT", Font.BOLD, 30));
                panel1.add(titel, new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
            }
            LoginJ.add(panel1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 0), 0, 0));

            //---- userlabel ----
            userlabel.setText("Username:");
            userlabel.setLabelFor(email);
            LoginJ.add(userlabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 0), 0, 0));
            LoginJ.add(email, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 0), 0, 0));

            //---- passlabel ----
            passlabel.setText("Password:");
            passlabel.setLabelFor(password);
            LoginJ.add(passlabel, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 0), 0, 0));
            LoginJ.add(password, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 0), 0, 0));
            LoginJ.add(vSpacer1, new GridBagConstraints(0, 5, 1, 2, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));

            //---- submit ----
            submit.setText("Submit");
            submit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    submitActionPerformed(e);
                    submitActionPerformed(e);
                }
            });
            LoginJ.add(submit, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 0), 0, 0));

            //---- forgotpass ----
            forgotpass.setText("Forgot Password?");
            LoginJ.add(forgotpass, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 0), 0, 0));

            //---- createacc ----
            createacc.setText("Create Account");
            LoginJ.add(createacc, new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 0, 0), 0, 0));
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - Tamara Turton
    private JPanel LoginJ;
    private JPanel panel1;
    private JLabel titel;
    private JLabel userlabel;
    private JTextField email;
    private JLabel passlabel;
    private JPasswordField password;
    private JPanel vSpacer1;
    private JButton submit;
    private JButton forgotpass;
    private JButton createacc;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}

最佳答案

您正在创建和自定义内容面板 - LoginJ,但未将其分配给框架。在 initComponents 方法的末尾,您应该执行以下操作:

this.setContentPane(this.LoginJ);

您将看到您的表单元素,然后您可以进一步自定义,例如放大对话框并使其居中。

关于java - JformDesigner-Eclipse Main 将无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26981917/

相关文章:

Eclipse 4.9 上的 Java 11 和 E(fx)clipse JavaFX 插件 : An error has occurred - see the log file

java - eclipse 插件中的 SWT 浏览器在 Mac 和 Windows 中的行为不同

java - 求除数的奇数

java - 整个程序的记录器打印消息两次,有时甚至打印更多次

java - Eclipse:Java 已启动但返回退出代码 -1073741571

java - Eclipse:在文本编辑器中使用UTF-8编码使字符串无法正常工作,我该如何解决这个问题?

java - 尝试安装插件时出错

java - 读取DOCX文件内容

java - 我正在尝试将 URL 图像添加到我的 javafx 应用程序中

java - 强制的?在 MySql 中为存储过程使用不同的定界符