在Netbeans中,我使用Jlabels在JFrame中顯示圖像和文本。 Jlabels在IDE中正確顯示,但是當我運行或構建項目時,某些Jlabel不顯示(稍後添加的標籤)。要解決這個問題,我必須重新開始,並一次添加圖像。這吸吮,因爲我從4到8,現在我需要添加20多個圖像。我真的不想重新開始。Netbeans JLabel圖標/文本在項目建立時不顯示
private void initComponents() {
mainPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
jButton2 = new javax.swing.JButton();
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
statusPanel = new javax.swing.JPanel();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
jLabel1 = new javax.swing.JLabel();
jFrame1 = new javax.swing.JFrame();
jLayeredPane2 = new javax.swing.JLayeredPane();
jLabel2 = new javax.swing.JLabel();
PC = new javax.swing.JLabel();
ALU = new javax.swing.JLabel();
BC = new javax.swing.JLabel();
DR = new javax.swing.JLabel();
MUXB = new javax.swing.JLabel();
MUXD = new javax.swing.JLabel();
RF = new javax.swing.JLabel();
IR = new javax.swing.JLabel();
ID = new javax.swing.JLabel();
bg = new javax.swing.JLabel();
mainPanel.setMaximumSize(new java.awt.Dimension(1000, 1000));
mainPanel.setMinimumSize(new java.awt.Dimension(800, 800));
mainPanel.setName("mainPanel"); // NOI18N
mainPanel.setPreferredSize(new java.awt.Dimension(900, 900));
statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(honors231.Honors231App.class).getContext().getResourceMap(Honors231View.class);
jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
jButton2.setName("jButton2"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(3055, 3055, 3055)
.addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1, Short.MAX_VALUE))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(305, 305, 305)
.addComponent(jButton2)
.addContainerGap(2678, Short.MAX_VALUE))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1470, 1470, 1470))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(11, 11, 11)
.addComponent(jButton2)
.addContainerGap(866, Short.MAX_VALUE))
);
menuBar.setMaximumSize(new java.awt.Dimension(60, 1000));
menuBar.setName("menuBar"); // NOI18N
fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
fileMenu.setName("fileMenu"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(honors231.Honors231App.class).getContext().getActionMap(Honors231View.class, this);
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
helpMenu.setName("helpMenu"); // NOI18N
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
statusPanel.setMaximumSize(new java.awt.Dimension(1000, 1000));
statusPanel.setMinimumSize(new java.awt.Dimension(800, 800));
statusPanel.setName("statusPanel"); // NOI18N
statusPanel.setPreferredSize(new java.awt.Dimension(1000, 28));
statusMessageLabel.setName("statusMessageLabel"); // NOI18N
statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
progressBar.setName("progressBar"); // NOI18N
javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(statusMessageLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 830, Short.MAX_VALUE)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusAnimationLabel)
.addContainerGap())
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(statusMessageLabel)
.addComponent(statusAnimationLabel)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
);
jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Davis\\Desktop\\cs231\\button0.png")); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jFrame1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jFrame1.setMinimumSize(new java.awt.Dimension(1600, 1000));
jFrame1.setName("jFrame1"); // NOI18N
jFrame1.setResizable(false);
jLayeredPane2.setBackground(resourceMap.getColor("jLayeredPane2.background")); // NOI18N
jLayeredPane2.setDoubleBuffered(true);
jLayeredPane2.setName("jLayeredPane2"); // NOI18N
jLabel2.setIcon(resourceMap.getIcon("jLabel2.icon")); // NOI18N
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
jLabel2.setBounds(160, 330, 380, 280);
jLayeredPane2.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
PC.setIcon(resourceMap.getIcon("PC.icon")); // NOI18N
PC.setText(resourceMap.getString("PC.text")); // NOI18N
PC.setName("PC"); // NOI18N
PC.setBounds(360, 40, 257, 227);
jLayeredPane2.add(PC, javax.swing.JLayeredPane.DEFAULT_LAYER);
ALU.setIcon(resourceMap.getIcon("ALU.icon")); // NOI18N
ALU.setText(resourceMap.getString("ALU.text")); // NOI18N
ALU.setName("ALU"); // NOI18N
ALU.setBounds(800, 490, 304, 300);
jLayeredPane2.add(ALU, javax.swing.JLayeredPane.DEFAULT_LAYER);
BC.setIcon(resourceMap.getIcon("BC.icon")); // NOI18N
BC.setText(resourceMap.getString("BC.text")); // NOI18N
BC.setName("BC"); // NOI18N
BC.setBounds(40, 40, 257, 227);
jLayeredPane2.add(BC, javax.swing.JLayeredPane.DEFAULT_LAYER);
DR.setIcon(resourceMap.getIcon("DR.icon")); // NOI18N
DR.setText(resourceMap.getString("DR.text")); // NOI18N
DR.setName("DR"); // NOI18N
DR.setBounds(1150, 570, 425, 320);
jLayeredPane2.add(DR, javax.swing.JLayeredPane.DEFAULT_LAYER);
MUXB.setIcon(resourceMap.getIcon("MUXB.icon")); // NOI18N
MUXB.setText(resourceMap.getString("MUXB.text")); // NOI18N
MUXB.setName("MUXB"); // NOI18N
MUXB.setBounds(1210, 350, 246, 186);
jLayeredPane2.add(MUXB, javax.swing.JLayeredPane.DEFAULT_LAYER);
MUXD.setIcon(resourceMap.getIcon("MUXD.icon")); // NOI18N
MUXD.setText(resourceMap.getString("MUXD.text")); // NOI18N
MUXD.setName("MUXD"); // NOI18N
MUXD.setBounds(710, 780, 246, 186);
jLayeredPane2.add(MUXD, javax.swing.JLayeredPane.DEFAULT_LAYER);
RF.setIcon(resourceMap.getIcon("RF.icon")); // NOI18N
RF.setText(resourceMap.getString("RF.text")); // NOI18N
RF.setName("RF"); // NOI18N
RF.setBounds(930, 0, 450, 330);
jLayeredPane2.add(RF, javax.swing.JLayeredPane.DEFAULT_LAYER);
IR.setIcon(resourceMap.getIcon("IR.icon")); // NOI18N
IR.setText(resourceMap.getString("IR.text")); // NOI18N
IR.setName("IR"); // NOI18N
IR.setBounds(460, 340, 300, 330);
jLayeredPane2.add(IR, javax.swing.JLayeredPane.DEFAULT_LAYER);
ID.setIcon(resourceMap.getIcon("ID.icon")); // NOI18N
ID.setText(resourceMap.getString("ID.text")); // NOI18N
ID.setName("ID"); // NOI18N
ID.setBounds(100, 670, 500, 227);
jLayeredPane2.add(ID, javax.swing.JLayeredPane.DEFAULT_LAYER);
bg.setIcon(resourceMap.getIcon("bg.icon")); // NOI18N
bg.setText(resourceMap.getString("bg.text")); // NOI18N
bg.setName("bg"); // NOI18N
bg.setBounds(0, 0, 1600, 1000);
jLayeredPane2.add(bg, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jFrame1Layout.createSequentialGroup()
.addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 1600, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(1714, Short.MAX_VALUE))
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jFrame1Layout.createSequentialGroup()
.addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 1002, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(869, Short.MAX_VALUE))
);
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>
嗯...我有一個非常類似的問題几几天前一些菜單項沒有顯示,我解決了同樣的問題。我想知道他們是如何相關的? – 2010-04-29 16:49:06