2016-04-21 20 views
1

Ich habe gerade ein einfaches Projekt auf NetBeans erstellt und eine GUI erstellt. Wenn ich das Projekt starte, erscheint ein Fenster, aber das ist nur eine leere Box. Ich habe nichts im Code geändert, einfach die GUI per Drag & Drop in NetBeans erstellt.JFrame zeigt aber ist leer

package twittersearch; 

public class TwitterSearchUI extends javax.swing.JFrame { 

public TwitterSearchUI() { 
    initComponents(); 
} 

@SuppressWarnings("unchecked") 
// <editor-fold defaultstate="collapsed" desc="Generated Code">       
private void initComponents() { 

    jButton1 = new javax.swing.JButton(); 
    jTextField1 = new javax.swing.JTextField(); 
    jScrollPane1 = new javax.swing.JScrollPane(); 
    jTextArea1 = new javax.swing.JTextArea(); 

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 

    jButton1.setText("Search"); 
    jButton1.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jButton1ActionPerformed(evt); 
     } 
    }); 

    jTextField1.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
      jTextField1ActionPerformed(evt); 
     } 
    }); 

    jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Results")); 

    jTextArea1.setColumns(20); 
    jTextArea1.setRows(5); 
    jScrollPane1.setViewportView(jTextArea1); 

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
    getContentPane().setLayout(layout); 
    layout.setHorizontalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(layout.createSequentialGroup() 
      .addContainerGap() 
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
       .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addGroup(layout.createSequentialGroup() 
        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE) 
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
        .addComponent(jButton1))) 
      .addContainerGap(26, Short.MAX_VALUE)) 
    ); 
    layout.setVerticalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(layout.createSequentialGroup() 
      .addContainerGap() 
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
       .addComponent(jButton1) 
       .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE) 
      .addContainerGap(19, Short.MAX_VALUE)) 
    ); 

    pack(); 
}// </editor-fold>       

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

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

}           

public static void main(String args[]) { 
    //<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(TwitterSearchUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (InstantiationException ex) { 
     java.util.logging.Logger.getLogger(TwitterSearchUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (IllegalAccessException ex) { 
     java.util.logging.Logger.getLogger(TwitterSearchUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
     java.util.logging.Logger.getLogger(TwitterSearchUI.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() { 
      new TwitterSearchUI().setVisible(true); 
     } 
    }); 
} 

// Variables declaration - do not modify      
private javax.swing.JButton jButton1; 
private javax.swing.JScrollPane jScrollPane1; 
private javax.swing.JTextArea jTextArea1; 
private javax.swing.JTextField jTextField1; 
// End of variables declaration     
} 
+0

ich das gleiche Bild gerade aufgenommen haben unten von Herrn Derb enthalten. Keine Änderungen in Ihrem Code erzeugen diese GUI, auf der Ihre Klasse läuft. – RubioRic

Antwort

2

mit genau diesem Code bekomme ich diese:

enter image description here

+0

Ich muss es falsch eingerichtet haben, ich habe meinen Code in ein neues Projekt kopiert und es funktioniert. Danke für den Tipp :) – Alfie

-1

Haben Sie eine bestimmte Größe (Breite, Höhe) festgelegt?

Verwandte Themen