Серый экран в Java Netbeans - Как мне предотвратить это? - PullRequest
0 голосов
/ 22 февраля 2019

В настоящее время я использую IDE NetBeans с JFrame.На IDE экран отрисовывается нормально.См. Прикрепленный снимок экрана. Рабочий экран, отображаемый в среде IDE Netbeans

Однако, когда я запускаю файл, у меня появляется серый экран.Смотрите прикрепленный скриншот. Изображение серого экрана

Ниже приведен код:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package groupchatapp;

/**
 *
 * @author Jim Ng
 */
public class ChatInterface extends javax.swing.JFrame {

    /**
     * Creates new form GroupChatGUI
     */


    /**
     * 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        TalkIcon = new javax.swing.JLabel();
        TalkIcon1 = new javax.swing.JLabel();
        usersLbl = new javax.swing.JLabel();
        GroupsLbl = new javax.swing.JLabel();
        GroupChatsLbl = new javax.swing.JLabel();
        groupNameLbl = new javax.swing.JLabel();
        groupLblWhiteBg = new javax.swing.JLabel();
        userLblWhiteBg = new javax.swing.JLabel();
        groupsScrollPane = new javax.swing.JScrollPane();
        groupChatList = new java.awt.List();
        groupNameScrollPane = new javax.swing.JScrollPane();
        allMessagesTextField = new java.awt.TextField();
        viewBtn = new java.awt.Button();
        deleteChatBtn = new java.awt.Button();
        editChatBtn = new java.awt.Button();
        createNewBtn = new java.awt.Button();
        typeMessageTextField = new java.awt.TextField();
        sendBtn1 = new java.awt.Button();
        addBtn1 = new java.awt.Button();
        GardensByTheBayBG = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        TalkIcon.setBackground(new java.awt.Color(255, 255, 255));
        TalkIcon.setForeground(new java.awt.Color(255, 255, 255));
        TalkIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/groupchatapp/TalkIcon.png"))); // NOI18N
        getContentPane().add(TalkIcon);
        TalkIcon.setBounds(310, 0, 190, 200);

        TalkIcon1.setBackground(new java.awt.Color(255, 255, 255));
        TalkIcon1.setForeground(new java.awt.Color(255, 255, 255));
        TalkIcon1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/groupchatapp/GroupIcon.png"))); // NOI18N
        TalkIcon1.setPreferredSize(new java.awt.Dimension(30, 30));
        getContentPane().add(TalkIcon1);
        TalkIcon1.setBounds(250, 210, 50, 50);

        usersLbl.setBackground(new java.awt.Color(255, 255, 255));
        usersLbl.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        usersLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        usersLbl.setText("Users");
        getContentPane().add(usersLbl);
        usersLbl.setBounds(610, 210, 130, 50);

        GroupsLbl.setBackground(new java.awt.Color(255, 255, 255));
        GroupsLbl.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        GroupsLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        GroupsLbl.setText("Groups");
        getContentPane().add(GroupsLbl);
        GroupsLbl.setBounds(70, 200, 160, 70);

        GroupChatsLbl.setBackground(new java.awt.Color(255, 255, 255));
        GroupChatsLbl.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        GroupChatsLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        GroupChatsLbl.setText("Group Name");
        getContentPane().add(GroupChatsLbl);
        GroupChatsLbl.setBounds(240, 200, 370, 70);

        groupNameLbl.setBackground(new java.awt.Color(255, 255, 255));
        groupNameLbl.setForeground(new java.awt.Color(255, 255, 255));
        groupNameLbl.setIcon(new javax.swing.ImageIcon(getClass().getResource("/groupchatapp/WhiteBackground.PNG"))); // NOI18N
        groupNameLbl.setText("Ty");
        getContentPane().add(groupNameLbl);
        groupNameLbl.setBounds(240, 210, 360, 50);

        groupLblWhiteBg.setBackground(new java.awt.Color(255, 255, 255));
        groupLblWhiteBg.setForeground(new java.awt.Color(255, 255, 255));
        groupLblWhiteBg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/groupchatapp/WhiteBackground.PNG"))); // NOI18N
        groupLblWhiteBg.setText("Ty");
        getContentPane().add(groupLblWhiteBg);
        groupLblWhiteBg.setBounds(70, 210, 160, 50);

        userLblWhiteBg.setBackground(new java.awt.Color(255, 255, 255));
        userLblWhiteBg.setForeground(new java.awt.Color(255, 255, 255));
        userLblWhiteBg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/groupchatapp/WhiteBackground.PNG"))); // NOI18N
        userLblWhiteBg.setText("Ty");
        getContentPane().add(userLblWhiteBg);


   userLblWhiteBg.setBounds(610, 210, 130, 50);

    groupsScrollPane.setViewportView(groupChatList);

    getContentPane().add(groupsScrollPane);
    groupsScrollPane.setBounds(70, 270, 160, 230);

    allMessagesTextField.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
    groupNameScrollPane.setViewportView(allMessagesTextField);

    getContentPane().add(groupNameScrollPane);
    groupNameScrollPane.setBounds(240, 270, 360, 190);

    viewBtn.setBackground(new java.awt.Color(255, 0, 0));
    viewBtn.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
    viewBtn.setForeground(new java.awt.Color(255, 255, 255));
    viewBtn.setLabel("View");
    getContentPane().add(viewBtn);
    viewBtn.setBounds(630, 460, 90, 40);

    deleteChatBtn.setBackground(new java.awt.Color(255, 0, 0));
    deleteChatBtn.setForeground(new java.awt.Color(255, 255, 255));
    deleteChatBtn.setLabel("Delete");
    getContentPane().add(deleteChatBtn);
    deleteChatBtn.setBounds(120, 540, 70, 20);

    editChatBtn.setBackground(new java.awt.Color(255, 0, 0));
    editChatBtn.setForeground(new java.awt.Color(255, 255, 255));
    editChatBtn.setLabel("Edit");
    editChatBtn.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            editChatBtnActionPerformed(evt);
        }
    });
    getContentPane().add(editChatBtn);
    editChatBtn.setBounds(160, 510, 70, 20);

    createNewBtn.setBackground(new java.awt.Color(255, 0, 0));
    createNewBtn.setForeground(new java.awt.Color(255, 255, 255));
    createNewBtn.setLabel("Create");
    createNewBtn.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            createNewBtnActionPerformed(evt);
        }
    });
    getContentPane().add(createNewBtn);
    createNewBtn.setBounds(70, 510, 70, 20);

    typeMessageTextField.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
    typeMessageTextField.setText("type your message here...");
    getContentPane().add(typeMessageTextField);
    typeMessageTextField.setBounds(240, 460, 360, 40);

    sendBtn1.setBackground(new java.awt.Color(255, 0, 0));
    sendBtn1.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
    sendBtn1.setForeground(new java.awt.Color(255, 255, 255));
    sendBtn1.setLabel("Send");
    getContentPane().add(sendBtn1);
    sendBtn1.setBounds(510, 510, 90, 40);

    addBtn1.setBackground(new java.awt.Color(255, 0, 0));
    addBtn1.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
    addBtn1.setForeground(new java.awt.Color(255, 255, 255));
    addBtn1.setLabel("Add");
    getContentPane().add(addBtn1);
    addBtn1.setBounds(410, 510, 90, 40);

    GardensByTheBayBG.setIcon(new javax.swing.ImageIcon(getClass().getResource("/groupchatapp/Singapore Garden City.jpg"))); // NOI18N
    getContentPane().add(GardensByTheBayBG);
    GardensByTheBayBG.setBounds(0, -210, 2260, 1090);

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

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

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

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<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(ChatInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ChatInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ChatInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ChatInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>
    //</editor-fold>
    //</editor-fold>
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new ChatInterface().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JLabel GardensByTheBayBG;
private javax.swing.JLabel GroupChatsLbl;
private javax.swing.JLabel GroupsLbl;
private javax.swing.JLabel TalkIcon;
private javax.swing.JLabel TalkIcon1;
private java.awt.Button addBtn1;
private java.awt.TextField allMessagesTextField;
private java.awt.Button createNewBtn;
private java.awt.Button deleteChatBtn;
private java.awt.Button editChatBtn;
private java.awt.List groupChatList;
private javax.swing.JLabel groupLblWhiteBg;
private javax.swing.JLabel groupNameLbl;
private javax.swing.JScrollPane groupNameScrollPane;
private javax.swing.JScrollPane groupsScrollPane;
private java.awt.Button sendBtn1;
private java.awt.TextField typeMessageTextField;
private javax.swing.JLabel userLblWhiteBg;
private javax.swing.JLabel usersLbl;
private java.awt.Button viewBtn;
// End of variables declaration                   

}

Могу ли я узнать, в чем проблема с моим кодом и почемуЯ выполнил рендеринг с серым экраном при запуске файла?

Я нахожусь на NetBeans 10.0.2, и это делается с помощью JFrame.

...