How to get a element from a image grid ?

Hi

I want a grid where I can get each element of the the grid. Currently I use a GridbaLayout where I add my images.

Any ideas??

thats the right way. Simply use any existing Image component you can find on the web, for example JXImagePanel from SwingX is one of them, I also made one on my own that is quite similar but with lesser functionalities such as Scaling or transparency, see at swinglabs.org.
Then add your image to the gridBag. Pay attention to the fact that it uses quite more memory heap than a simple GRidBag with usual component.

Well, I offer you a sample of my own impl of this:

/***/
    private void loadModelPanel(SpritesCacheManager<Integer, Animation> mc3) throws NullPointerException{
        modelPanel.removeAll();
        final SpritesCacheManager<Integer, Animation> model = mc3;
        GridBagConstraints c = new GridBagConstraints();
        c.gridwidth = GridBagConstraints.REMAINDER;
        Map<Integer, File> cache = mc3.getSwapMap();
        int width = 3; int n = 0;
        for(Integer key : cache.keySet()) {
            final int record = key;
            Animation current = mc3.get(key);
            final JXImagePanel anim = new JXImagePanel();
            anim.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    currentAnim = model.get(record);
                    anim.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.BLUE, Color.GREEN));
                }
            });
            anim.setDoubleBuffered(true);
            anim.setImage(current.getImage());
            anim.setPreferredSize(current.getSize());
            anim.setStyle(JXImagePanel.Style.SCALED);
            JXTitledPanel panel = new JXTitledPanel(current.startingFrame + " - " + (current.startingFrame + current.length) + " (" + current.realTimeLength() + "ms)", anim);
            panel.setPreferredSize(new Dimension(current.getSize().width, current.getSize().height + 10));
            modelPanel.add(panel);
            if((n % width) == (width-1))
                ((GridBagLayout)modelPanel.getLayout()).setConstraints(panel, c);
            modelPanel.validate();
            n++;
        }
    }
    

let’s see what you can do! ;D