public void paintItems()
{
ArrayList inRoomItems = ((Room) scenery.getCurrentRoom()).getItemsArray();
Point origin = new Point(380, 10);
int layerNumber = 50;
int numberHorizontally = 0;
int n=inRoomItems.size();
for(int i=0; i<n; i++){
image = new JLabel(((Item) inRoomItems.get(i)).getImageIcon());
imagePane.add(image, new Integer(layerNumber));
image.setOpaque(false);
image.setBounds(origin.x, origin.y, 100, 100);
origin.y += 90;
numberHorizontally++;
if (numberHorizontally % 3 ==0){
origin.x -= 100;
origin.y = 10;
}
layerNumber ++;
}
}
I am having a problem displaying images in GUI. I have a borderLayout, and on the right (.EAST) I am displaying ImageIcons of my inventory. here is the code I am using:
public void paintInventoryItems()
{
itemPane.removeAll();
setInventoryLabel();
HashMap items = scenery.getInventory();
Iterator it = items.keySet().iterator();
while (it.hasNext()){
String key = (String) it.next();
JLabel item = new JLabel (((Item) items.get(key)).getImageIcon());
item.setBorder(new EmptyBorder(4,0,4,0));
itemPane.add(item);
}
frame.pack();
}
The problem is that each ImageIcon appears with a different size, so one is small, and others are big and the first doesnt start at the top, but in the middle!
any help with setting the size and the coordination they appear with?
thanks!