Search code examples
javaiconsoutputanimated-gifnetbeans-platform

Add .gif image as icon to the output window


I want to add a loading animated gif icon to the output window of my NetBeans platform application that I am developing. I managed to add a png icon file. But in this case, the gif icon added is not animating. it stays the same.

private class Loading extends AbstractAction {

        public Loading() {
            //putValue(SMALL_ICON, ImageUtilities.loadImageIcon("org/netbeans/modules/plsql/execution/loading.gif", true));

            putValue(SMALL_ICON, ImageUtilities.loadImage("org/netbeans/modules/plsql/execution/loading.gif",true));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Action performed");
        }

    }

This is what I used as the output window.

final InputOutput io = IOProvider.getDefault().getIO("Deploy Dependents", new Action[]{new Loading()});

To the image that is circled here


Solution

  • You need to add the button as the ImageObserver of the Image you loaded with ImageUtilities.loadImage(). It will take care of the animation for you.

    Access to the button itself might be hidden by the IOProvider class but if you manage to get a handle on it, just call image.setImageObserver(button) and you'll see the animation running.