I have a grid layout on which I have added 100 Jbuttons.Now I require to have the buttons without any margin or gap among them.What I tried is here :
private void initializeBoard() {
container = getContentPane();
container.setLayout(new GridLayout(1,2));
boardPanel = new JPanel(new GridLayout(10,10));
dataPanel = new JPanel();
int index = 0;
for(int i=0;i<BOARD_SIZE;i++){
for(int j=0;j<BOARD_SIZE;j++){
squares[i][j] = new JButton(String.valueOf(numbers[index]));
squares[i][j].addActionListener(this);
squares[i][j].setMargin(new Insets(0,0,0,0));
squares[i][j].setBorder(BorderFactory.createEmptyBorder());
squares[i][j].setBorderPainted(false);
squares[i][j].setContentAreaFilled(false);
squares[i][j].setFocusPainted(true);
squares[i][j].setIcon(new ImageIcon("images/board/"+numbers[index++]+".jpg"));
boardPanel.add(squares[i][j]);
}
}
boardPanel.setBorder(BorderFactory.createEmptyBorder());
container.add(boardPanel);
container.add(dataPanel);
}
But the result is like this.I still get vertical gaps among the buttons.
I need to eliminate this gaps so that I get no gaps among the buttons and get the buttons to represent the whole board.
Thanks in advance.
EDIT Got it.The images I was using was not wide enough to fill those areas.Thanks.