How can i display a image on a small jbutton.
I am trying to create a minesweeper game. I have used jb.setBounds(0,0,20,20) on the jbuttons in the minesweeper field.
To display the image of the flag I use ...
jb.setIcon( new ImageIcon( "flag.gif" ) );
and to display numbers i use ...
jb.setText( "" + i );// i is an integer variable.
But I am not able to display either the image or the text. All that is displayed in both the cases are 3 small dots near the bottom of the jbutton in minesweeper field. When i use a bigger size for the jbuttons, I have no problem. Is there a way to get around this problem.
I am only a novice, so if I am using a wrong approach or u have a better approach please suggest it to me. Please also suggest someway to keep the size of grid constant in different resolutions.
[803 byte] By [
RDXa] at [2007-11-26 18:05:34]

# 2
> All that is displayed in both the cases are 3 small dots
1) get rid of the margin
button.setMargin(new Insets(0,0,0,0));
2) change to a smaller font size
button.setFont(button.getFont().deriveFont(8f));
> Please also suggest someway to keep the size of grid constant in different resolutions.
use a layout manager
# 3
Thanks a lot guys!
Using setMargin() alone solved my problem.
But will you elaborate how using a layout manager will help in keeping the grid size constant. I am using GridBagLayout() to construct the grid. But the size of grid depends on the size of the buttons it is made of. And i have to use number of pixels to specify the size of buttons e.g. setPreferredSize(20,20).
Is there a way to specify size in physical units like cms, inches, etc.
RDXa at 2007-7-9 5:36:13 >
