java awt 或 Swing 组件丢失或未显示

java awt or Swing component missing or not shown

我负责一个新的软件工具,我正在尝试测试它。

问题: 我注意到我的 GUI 和服务器上工具 运行 的 GUI 之间存在差异: 缺少一个组件! 就像它没有显示一样,因为我进入了调试模式,一切似乎都很好。 此图显示不同之处:

如您所见,"Shaft end Dia" 组件在其他 2 个组件之间缺失。

代码: 这是代码部分。有很多项目以相同的方式实例化和添加,但它在我的电脑上不适用(但它们在其他电脑上运行良好!!)

//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表示没有出现)

  3. 运行通过 .bat 文件在服务器上安装 jar:WORKS

  4. 运行通过cvs下载代码,在同事电脑上通过eclipse安装jar:WORKS
  5. 运行在同事的计算机上通过 .bat 将 jar 交给他我的文件:WORKS
  6. 运行在同事的电脑上通过.bat编译jar,文件自己编译:WORKS
  7. 在我的代码上评论之前的 panelColumn:可行!!!!

注意: 1) java 版本:1.7.0.75(在我的电脑上或者在我同事的电脑上) 2) OS: window Vbox 7(我和同事) 3) Eclipse Luna 4.x(两者的版本相同)

问题: 有没有人遇到过这种问题? 知道如何解决吗?

提前谢谢大家!

您必须使用 setBounds()

方法增加面板的面积 myInputPanel