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:
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);
}
}
A FlowLayout uses a gap of 5 pixels between the border of the parent container and the child components.
You can either:
Use a FlowLayout
, but set this gap to 0 pixels. Read the FlowLayout API to see the constructor parameters for this.
Use a BorderLayout
on your panel.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.