Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing White Gap Under Title Bar

I am creating a simple Java GUI with Swing and I have a white bar that appears under the title bar that I can't seem to figure out how to get rid of. I appreciate any help and tips as I have searched all over for anyone with a similar problem and have not been able to find anything. Thanks

Image of Java GUI:

http://s21.postimg.org/vdo7ju37b/image.png

import javax.swing.*;
import java.awt.*;

public class ja {

    public static void main(String[] args) {
            JFrame f = new JFrame("jA");
            JPanel p = new JPanel();
            p.setLayout(new FlowLayout());
            f.setSize(400, 600);
            f.setLocationRelativeTo(null);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JLabel bg = new JLabel(new ImageIcon("brown.jpg"));
            bg.setLayout(new FlowLayout());
            p.add(bg);

            JButton b1 = new JButton("b1");
            JButton b2 = new JButton("b2");
            JButton b3 = new JButton("b3");

            bg.add(b1);
            bg.add(b2);
            bg.add(b3);

            f.add(p);

            f.setVisible(true);
    }
}
like image 453
user282902 Avatar asked Jul 22 '26 14:07

user282902


1 Answers

A FlowLayout uses a gap of 5 pixels between the border of the parent container and the child components.

You can either:

  1. Use a FlowLayout, but set this gap to 0 pixels. Read the FlowLayout API to see the constructor parameters for this.

  2. Use a BorderLayout on your panel.

like image 167
camickr Avatar answered Jul 24 '26 05:07

camickr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!