所以我确实浏览了一下并看到了一些与我类似的问题,但对他们有用的修复仍然无法为我显示窗口。我正在尝试创建一个登录屏幕,这是生成的代码,我从以前的问题中复制了公共静态主电源,但它仍然只显示一个最小大小的窗口,其中没有任何内容:
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);
您将看到表单元素,然后您可以进一步自定义,例如放大和居中对话框。