I tried to program a small TicTacToe and gave the buttons I used for the game an icon depending on which player marked that button (you know, the traditional cross and circle).
Now, when I check my buttons "in game", the icons are a little bit off; there is a small (maybe 10 px big) gap between the icon and the button border.
I already tried this but it didn't work:
button.setHorizontalAlignement(SwingConstants.RIGHT)
Example Code:
JButton button = new JButton();
button.setPreferredSize(new Dimension(175,175)); //Note: Image is also 175x175
button.addActionListener(new MyOnClickListener());
...
class MyOnClickListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
JButton button = (JButton) e.getSource();
ImageIcon myIcon = new ImageIcon("source");
button.setEnabled(false);
button.setIcon(myIcon);
button.setDisabledIcon(myIcon);
}
}
See that little white margin to the right? This is what i don't want. I want the icon to fill the button completely. Here's the icon: Icon