SetVisible没有显示第二个JFrame

时间:2013-05-25 23:07:19

标签: java swing jframe visible

我创建了一个JFrame,当执行按钮操作时,调用第一个JFrame的构造函数中实例化的第二个JFrame,并且在此执行的操作中只有setVisible(true)但是没有显示,我不确定我做错了所以...在这里我点击了我的代码的一小部分:

主要JFrame

public Main() {
    initComponents();
    Datos datos = new Datos();
}

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           

        datos.setVisible(true);
}  

第二帧

public class Datos extends javax.swing.JPanel {

/**
 * Creates new form Datos
 */
public Datos() {
    initComponents();
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jTextUser = new javax.swing.JTextField();
    jTextPass = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jTextURL = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jButtonOK = new javax.swing.JButton();
    jButtonCancelar = new javax.swing.JButton();

    jTextUser.setText("jTextField1");

    jTextPass.setText("jTextField2");

    jLabel1.setText("Usuario:");

    jLabel2.setText("Contraseña:");

    jTextURL.setText("jTextField1");
    jTextURL.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jTextURLActionPerformed(evt);
        }
    });

    jLabel3.setText("URL del repositorio:");

    jButtonOK.setText("OK");

    jButtonCancelar.setText("Cancelar");

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .add(80, 80, 80)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jLabel3)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jTextURL)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel2)
                            .add(jLabel1))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jTextUser)
                            .add(jTextPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 141, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
            .addContainerGap(92, Short.MAX_VALUE))
        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
            .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jButtonOK)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(jButtonCancelar)
            .add(28, 28, 28))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
            .addContainerGap(67, Short.MAX_VALUE)
            .add(jLabel3)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(jTextURL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jTextUser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(jLabel1))
            .add(18, 18, 18)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jTextPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(jLabel2))
            .add(51, 51, 51)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jButtonOK)
                .add(jButtonCancelar))
            .add(23, 23, 23))
    );
}// </editor-fold>                        

private void jTextURLActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
}                                        

// Variables declaration - do not modify                     
private javax.swing.JButton jButtonCancelar;
private javax.swing.JButton jButtonOK;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextPass;
private javax.swing.JTextField jTextURL;
private javax.swing.JTextField jTextUser;
// End of variables declaration                   

}

0 个答案:

没有答案