I’m doing something like this:
JFrame frame = new JFrame();
frame.setSize(216, 272);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jp = new JPanel();
GridLayout gl = new GridLayout(10, 2);
jp.setLayout(gl);
//this an an 18x18 png
Image img = ImageIO.read(new File("C:\\Users\\Josh\\workspace\\src\\red.png"));
for(int ii=0; ii < 20; ii++)
{
JPanel buttonPanel = new JPanel();
JButton jb1 = new JButton(new ImageIcon(img));
jb1.setBorder(BorderFactory.createEmptyBorder());
buttonPanel.add(jb1);
jp.add(buttonPanel);
}
frame.add(jp);
Which produces:

No matter how I resize the image or use a frame.size() I can’t get the vertical gaps to go away. There is always space between the top of one block and the bottom of another.

Does anyone know how I can remove the spaces between the bottom of one button and the top of the next button?
Start by specifying the vertical (and horizontial) spacing for
GridLayoutvia the constructor.Next, you need to strip away all the unrequired content of the buttons…
Then you should be set.
Updated with individual panels
The default layout for a panel is
FlowLayout, you need something that isn’t going to add more padding, something likeBorderLayoutor evenGridBagLayout