简体   繁体   中英

java awt or Swing component missing or not shown

i've been charged with a new software tool, and im trying to test it.

PROBLEM: I noticed a difference between mine GUI and the GUI of the tool run on the server: a component is missing! It is like if it's not shown, because i went in debug mode, and everything seems to be fine. this image shows the different:

不同

as you can see, the "Shaft end Dia" component is missing between the others 2 components.

CODE: here is a code part. There are lots of items that get instantiate and added in the same way, but it doesn't apper on my pc (but they works well in others!!)

//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;
}

}

What i tried to do is:

  1. running it via my Eclipse: FAIL
  2. running the jar via .bat file: FAIL (FAIL means it doesn't appear)

  3. running the jar on the server via .bat file: WORKS

  4. running the jar via eclipse on a colleague's computer by downloading the code via cvs: WORKS
  5. running the jar via .bat on colleague's computer giving him my files: WORKS
  6. running the jar via .bat on colleague's computer with files compiled by himself: WORKS
  7. commenting the previous panelColumn on my code: WORKS!!!!

NOTE: 1) java version: 1.7.0.75 (either on mine pc either on my collegue pc) 2) OS: window 7 on Vbox (either me and collegue) 3) Eclipse Luna 4.x (same version again for both)

QUESTION: Has anyone had this kind of problems? Any idea about how to solve it?

Thank you all in advance!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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