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!

Recommended Answers

All 3 Replies

I used setBounds() method, set the size to a constant for each item, but I still get a difference in size!

Do your original images that used as icons are different sizes? If so, you may need to scale it before you add to the JLabel, or simply scale the size of images and resave them yourself.

you dont even know how helpful that was! thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.