2015-02-23 41 views
0

我一直在負責一個新的軟件工具,而我會嘗試測試它。的Java AWT或Swing組件缺失或不顯示

問題: 我注意到我的GUI和服務器上運行的工具的GUI之間的區別: 組件丟失了! 這就好像它沒有顯示,因爲我進入調試模式,並且一切似乎都很好。 這個圖像顯示了不同:

different

,你可以看到,在「軸端直徑」組件在其他2個組件之間失蹤。

CODE: 這裏是一個代碼的一部分。有很多是那些獲得實例,並用同樣的方法添加的項目,但它並不在我的電腦衝擊片雷管(但效果很好的人!)

//PanelContainerClass 
public class myInputPanel extends JPanel { 
//myInputPanel fields 
private JPanel myPanelMissing = null; 
private JLabel jLabel_ofPanelMissing = null; 

//myInputPanel is added to the mainFrame. 
public myInputPanel() { 
    super(); 
    initialize(); 
} 

private void initialize() { 
    //a GridBagConstraints is created for each panel i m going to add to myInputPanel 
    GridBagConstraints gbc6 = new GridBagConstraints(); 
    gbc6.gridx = 6; 
    gbc6.ipadx = 46; 
    gbc6.fill = GridBagConstraints.BOTH; 
    gbc6.insets = new Insets(0, 0, 0, 0); 
    gbc6.ipady = 0; 
    gbc6.gridy = 1; 
    //in a similiar way others gbc are instantiate 

    //a layout is given to myInputPanel 
    GridBagLayout gridBagLayout = new GridBagLayout(); 
    gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 176, 0, 63, 0, 0, 0, 0, 0, 0, 0}; 
    this.setLayout(gridBagLayout); 
    this.setSize(1185, 120);   
    this.setPreferredSize(new Dimension(1164, 143)); 
    this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 


    // add others panels to myInputPanel using this.add(getPanel_X(), gridBagConstraintsN); 
    this.add(getmyPanelMissing(), gridBagConstraints6); 
    // add others panels to myInputPanel using this.add(getPanel_Y(), gridBagConstraintsM); 

} 

private JPanel getmyPanelMissing() { 
    if (myPanelMissing == null) { 
     //in debug it get inside the if 
     jLabel_ofPanelMissing = new JLabel(); 
     jLabel_ofPanelMissing.setHorizontalAlignment(SwingConstants.CENTER);    
     jLabel_ofPanelMissing.setText("<html><body>" +     
       "<table cellspacing='0';cellpadding='0';> <tr> <td align='center'>Shaft end Dia</td> </tr> <tr> <td align='center'>[mm]</td> </tr></table>" +       
       "</body></html>"); 
     GridLayout lay = new GridLayout(); 
     lay.setRows(1); 
     myPanelMissing = new JPanel(); 
     myPanelMissing.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED)); 
     myPanelMissing.setLayout(lay); 
     myPanelMissing.add(jLabel_ofPanelMissing, null); 
    } 
    return myPanelMissing; 
} 

}

了我所要做的是:

  1. 通過我的Eclipse中運行它:失敗
  2. 通過.bat文件運行的jar:FAIL (FAIL意味着它不會出現)

  3. 通過.bat文件在服務器上運行的jar:WORKS

  4. 由通過CVS下載代碼運行通過同事的電腦上日食的jar:WORKS
  5. 同事的電腦給他上通過蝙蝠運行的jar我的文件:作品
  6. 通過.bat在同事的計算機上運行jar,並自行編譯文件:WORKS
  7. 評論我的代碼上的panelColumn:WORKS !!!!

注: 1)Java版本:1.7.0.75(無論是在礦井PC無論是在我的collegue PC) 2)OS:窗口7 VBOX(無論是我和collegue) 3)Eclipse的月神4。 X(同樣再爲兩個版本)

問題: 有沒有人有這樣那樣的問題? 有關如何解決它的任何想法?

謝謝大家提前!

+1

*「關於如何解決它的主意?」 *(可能)修復代碼。爲了更快地獲得更好的幫助,請發佈[MCVE](http://stackoverflow.com/help/mcve)(最小完整可驗證示例)或[SSCCE](http://www.sscce.org/)(Short,Self Contained ,正確的例子)。 – 2015-02-23 14:30:57

+0

它不能是一個代碼問題,否則它會在服務器和我的同事計算機上給出相同的問題,但它不會。 – Koop4 2015-02-23 14:40:27

+1

*「它不可能是一個代碼問題」 *鬼才。*「否則將給予同樣的問題。」 *的問題將是隨機的,如果核心問題是'null'佈局,不要正對GUI代碼美國東部時間,設置首選尺寸... – 2015-02-23 14:59:06

回答

0

你必須增加你的面板myInputPanel的面積與方法setBounds()

+0

非常感謝您,您發現問題! 父組件的大小不足以顯示所有內容,增加它的大小解決了問題! – Koop4 2015-02-24 12:51:18

+0

請參閱[我是否應避免使用Java Swing中的set(Preferred | Maximum | Minimum)Size方法?](http://stackoverflow.com/q/7229226/418556)(是)。該建議雙倍適用於'setSize (..)'。 – 2015-02-27 01:23:18