JButtons had the default size and I can't change it. I was try with setSize and it don't do anything. When I click on some of JButtons picture will be set and the JButtons will get size of the picture. I want to set size of JButton to be the same like the size of JButton when I click on it(JButton with picture)
btn=new JButton[9];
j=0;
for (i = 0; i <btn.length; i++) {
btn[i] = new JButton("");
btn[i].addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(j%2==0){
((JButton) e.getSource()).setIcon(new ImageIcon("resources/X.png"));
}else{
((JButton) e.getSource()).setIcon(new ImageIcon("resources/O.png"));
}
((JButton) e.getSource()).setEnabled(false);
j++;
}
});
}
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=0;
p2.add(btn[0],gbc);
gbc.gridx=1;
gbc.gridy=0;
p2.add(btn[1],gbc);
gbc.gridx=2;
gbc.gridy=0;
p2.add(btn[2],gbc);
.........