0

I use BorderLayout, I put something in north and something in south, but there always has a white line between this two panel (north and south), how to delete this line?

I have try to setVGap and set HGap for BorderLayout and I have try to set the background color for the parent frame, that don't work either

Thank you for your help, now i put some code here, maybe you can see something wrong.

public class MediaSelector extends 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);
}

}

Douglas B. Staple
  • 10,510
  • 8
  • 31
  • 58
Nasri
  • 99
  • 10

1 Answers1

3

Actually, works fine for me. Must be something else your doing.

enter image description here

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

    }

}

Before you ask, you will need to share an example of your code before we can help your further

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366