繁体   English   中英

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

[英]java awt or Swing component missing or not shown

我已经被指控使用一种新的软件工具,而我正在尝试对其进行测试。

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

不同

如您所见,其他两个组件之间缺少“轴端直径”组件。

代码:这是代码部分。 有很多项目都以相同的方式实例化和添加,但是在我的电脑上没有包装(但是在其他产品上效果很好!)

//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:
  5. 在同事的计算机上通过.bat运行jar,给他我的文件:
  6. 通过.bat在同事的计算机上运行jar并使用他自己编译的文件:WORKS
  7. 在我的代码上评论上一个panelColumn:WORKS !!!!

注意:1)Java版本:1.7.0.75(在我的个人计算机上还是在我的同事计算机上)2)操作系统:Vbox上的窗口7(我和同事)3)Eclipse Luna 4.x(两者都再次使用相同版本)

问题:有人遇到过此类问题吗? 关于如何解决的任何想法?

谢谢大家!

您必须使用setBounds()方法增加面板myInputPanel的面积。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM