0 top margin on JPanel

Is there a way to add 0 margin / padding to a JPanel so that it matches the WHOLE screen?

Here's what I'm talking about: (see the small space above the panel, why doesn't it cover this too?) see the space above?

Here's how it is configured:

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)); 

and this is how it happens:

 } 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(); } 

So how can I fix this small gap?

+6
java swing
source share
1 answer

By default, all containers use the FlowLayout layout FlowLayout . FlowLayout defines hgap and vgap to separate components. Try the following:

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

It is strange, however, that there is no horizontal gap on the left.

+6
source share

All Articles