【问题标题】:java awt or Swing component missing or not shownjava awt 或 Swing 组件丢失或未显示
【发布时间】:2015-04-24 21:30:18
【问题描述】:

我负责开发一个新的软件工具,我正在尝试对其进行测试。

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

如您所见,其他 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:WORKS!!!!

注意: 1)java版本:1.7.0.75(在我的电脑上或者在我的同事电脑上) 2)操作系统:Vbox上的窗口7(我和同事) 3) Eclipse Luna 4.x(两个版本相同)

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

提前谢谢大家!

【问题讨论】:

  • “知道如何解决它吗?”(可能)修复代码。为了尽快获得更好的帮助,请发布MCVE(最小完整可验证示例)或SSCCE(简短、独立、正确的示例)。
  • 这不可能是代码问题,否则它会在服务器和我同事的计算机上出现同样的问题,但事实并非如此。
  • “这不可能是代码问题”著名的遗言.. “否则它会给出同样的问题..” 问题将是如果核心问题是null 布局,则随机,GUI 代码不在 EDT 上,设置首选尺寸 ...
  • 我没听懂你想表达的意思。但是,如果您想在工作代码上浪费时间,那就去做吧,我会连续给您发布代码流。
  • 您还没有发布MCVE 或“SSCCE”,所以我们无法提供帮助。

标签: java eclipse swing awt


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-07
  • 1970-01-01
  • 2012-01-20
  • 1970-01-01
  • 2021-12-07
相关资源
最近更新 更多