2010-08-20 17 views
6

C'è un modo per aggiungere 0 margine/riempimento a un JPanel in modo che si adatti alla schermata WHOLE che si suppone?0 margine superiore su JPanel

Ecco cosa sto parlando: (? Vedi il poco spazio sopra il pannello perché non si copre anche quello?) see the space above?

Ecco il modo in cui è messa a punto:

 labelStatus = new JLabel("\n\nSorry, the server crashed!"); 

     labelStatus.setForeground(Color.WHITE.brighter()); 
     statusPanel = new JPanel(); 
     statusPanel.setBackground(Color.RED.darker()); 
     statusPanel.add(labelStatus); 
     statusPanel.setPreferredSize(new Dimension(513,352)); 

e questo è come viene iniated:

} catch (Exception rwe) { 
        // System.exit(0); 
        game.add(statusPanel); 
        game.remove(yPanel); 
        game.remove(xPanel); 
        game.remove(roomPanel); 
        game.remove(userPanel); 
        game.remove(titlePanel); 
        game.remove(introPanel); 
      statusPanel.setOpaque(true); 
      labelStatus.setVisible(true); 
        System.out.println("Server went down -- crap!"); 
        c.append("\nServer crashed!"); 
        rwe.printStackTrace(); 
      } 

Quindi .. come posso risolvere quel piccolo gap?

risposta

6

Per impostazione predefinita, tutti i contenitori utilizzano il gestore di layout FlowLayout. FlowLayout specifica un hgap e un vgap per separare i componenti. Prova questo:

 
((FlowLayout)game.getLayout()).setVgap(0); 

È strano, tuttavia, che non ci sia spazio orizzontale sulla sinistra.

Problemi correlati