javax.swing, ImageIcon question
I'm working on a game in java which i've done most of the programming for. Now I'm trying to work on the GUI - something i've never worked for in java, and when I asked, I was told i should use swing for my GUI, which looks about right - it's turn-based and won't be particularly fancy. I want a few things listed on the window, along with a textbox, and a visual map - and it's that map which is giving me the problem. Basically, i have an 800x600 window, and starting in the top left corner i want to have a 15x15 array of 'tiles' to make up the map. These 'tiles' are 32x32 .png files, so it comes out to 480x480 which leaves room for other things. I've been looking at the tutorials on swing ( http://java.sun.com/docs/books/tutorial/uiswing/TOC.html to be specific) and this is what i came up with.
publicstaticvoid addComponentsToPane(Container pane){
pane.setLayout(null);
ImageIcon icon = createImageIcon("images/Tile1.png","grass");
JLabel mapLabels[][] =new JLabel[15][15];
for (int x = 0; x < 15; x++)
for (int y = 0; y < 15; y++){
mapLabels[x][y] =new JLabel(icon);
mapLabels[x][y].setBounds(x*32,y*32,(x+1)*32,(y+1)*32);
}
for (int x = 0; x < 15; x++)
for (int y = 0; y < 15; y++)
pane.add(mapLabels[x][y]);
}
this is the segment of code that's putting an ImageIcon array (later to be more varied than what it currently is...) on the screen. I can give the whole class if you need it, but its really not much of a departure from some of the ones in the tutorial.
here is a screenshot of the problem i have:
http://img.photobucket.com/albums/v682/sqpat17/tiles.png
Basically it's that empty space i'm wondering about how to get out. I tried changing the bounds, and this worked when i got down to defining the label boundaries as multiples of 21, but not only did this not make sense (why 21 instead of 32?), it came out a little weird:
http://img.photobucket.com/albums/v682/sqpat17/tiles2.png
I'm thinking i need to either figure out a way to put more than one image icon on a single label, use something other than labels, or just figure out how to get rid of that empty space in some other way. Im using labels because they seem to be the most basic items i can put on a frame that hold ImageIcons. Anyways, help would be greatly appreciated :)

