0

我用BorderLayout,我在北边放东西,在南边放东西,但这两个面板(南北)之间总是有一条白线,如何删除这条线?

我已经尝试setVGap设置HGapBorderLayout尝试设置父框架的背景颜色,但这也不起作用

感谢您的帮助,现在我在这里放了一些代码,也许您会发现有问题。

公共类 MediaSelector 扩展 JPanel{

public MediaSelector() {

    setBorder(new EmptyBorder(-1, -1, 0, -2));
    setBackground(Color.red);
    setLayout(new BorderLayout());
    JPanel panel1 = new JPanel();
    panel1.setBackground(new Color(home_screen_r,home_screen_g,home_screen_b));
    panel1.setLayout(null);

    JPanel buttonPane = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    buttonPane.setLayout(gridbag);
    buttonPane.setBackground(new Color(footer_r, footer_g, footer_b));

    add("North", panel1);
    add("South", buttonPane);
}
main(){
    mediaSelectorPane = new MediaSelector();
    mediaSelectorPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(mediaSelectorPane);
    if (isFullScreen) {
        frame.dispose();
        frame.setUndecorated(true);
        frame.getGraphicsConfiguration().getDevice()
                .setFullScreenWindow(frame);
        frame.setVisible(true);
}

}

4

1 回答 1

3

实际上,对我来说效果很好。一定是你在做的其他事情。

在此处输入图像描述

public class TestLayout19 {

    public static void main(String[] args) {
        new TestLayout19();
    }

    public TestLayout19() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                }

                JPanel north = new TestPane(Color.RED);
                JPanel center = new TestPane(Color.GREEN);
                JPanel south = new TestPane(Color.BLUE);

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                frame.add(north, BorderLayout.NORTH);
//                frame.add(center, BorderLayout.CENTER);
                frame.add(south, BorderLayout.SOUTH);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

    public class TestPane extends JPanel {

        public TestPane(Color bg) {
            setBackground(bg);
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(100, 100);
        }

    }

}

在您询问之前,您需要先分享一个代码示例,然后我们才能进一步帮助您

于 2013-03-07T06:15:46.493 回答