开发者

0 top margin on JPanel

开发者 https://www.devze.com 2023-01-12 23:45 出处:网络
Is there any way to add 0 margin/padding to a JPanel so it fits the WHOLE screen it\'s suppose? Here is what I am talking about: (see the little space above the panel? why doesn\'t it cover that as w

Is there any way to add 0 margin/padding to a JPanel so it fits the WHOLE screen it's suppose?

Here is what I am talking about: (see the little space above the panel? why doesn't it cover that as well?)

0 top margin on JPanel

Here is the way it's setup:

        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开发者_如何学C is how it gets 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();
            }

So.. how do I fix that small gap?


By default, all containers use the layout manager FlowLayout. FlowLayout specifies an hgap and a vgap to separate components. Try this:

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

It's strange, though, that there's no horizontal gap on the left.

0

精彩评论

暂无评论...
验证码 换一张
取 消