I would like to zoom in & zoom out an image in JLayeredPane. Now I have a snippet for loading a background image into JLayeredPane. How could I now access ALL content images of JLayeredPane (it could contain multiple images) and zoom them in/out? Perhaps, somebody could send me a good web-link? Thanks!

private void loadBackground() {
        JFileChooser fc = new JFileChooser("c:/");
        ImageFilter filter = new ImageFilter();

        int returnVal = fc.showDialog(this, "Load");

        if (returnVal == 0) {
            File selFile = fc.getSelectedFile();
            String pathToFile = selFile.getPath();
            try {
                final ImageIcon icon = new ImageIcon(pathToFile);
                JLabel bkg = new JLabel(icon);
                bkg.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
                MainClass.getBackgroundPane().add(bkg, new Integer(2), 0);
            } catch (Exception e) {
        } else
            System.out.println("The file is not selected.");

I see you are using ImageIcons in JLabels to show the images. Here's how I would think of this:
I'd create a subclass of JLabel that has an Image and a zoom ratio as instance variables. I'd use getScaledInstance to scale the Image according to the zoom ratio in a setZoom(float ratio) method and use that to update the ImageIcon.
I could have any number of these and use an ArrayList to track them all if necessary.
getScaledInstance has some bad press, although I've found it to be OK, but heres a link to ways round that

This article has been dead for over six months. Start a new discussion instead.