[英]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;
}
}
我試圖做的是:
通過.bat文件運行jar:FAIL(失敗表示未出現)
通過.bat文件在服務器上運行jar: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.