Search code examples
javaswingjinternalframenimbusuimanager

How can I change the "minimize, maximize and close" icons of a internal frame with Nimbus Laf?


I'm using Nimbus Look and Feel, I know how to change for example, the tooltip color, by using this code:

UIManager.put("info", Color.white);

But how can I change the icons (minimize, maximize and close) to another icon/png file?

Here is the the key of the close button: InternalFrame:InternalFrameTitlePane:"InternalFrameTitlePane.closeButton"[Enabled].backgroundPainter the same as info back there.

And here is the site with all Keys: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html#primary


Solution

  • Looks like a ugly Hack, but works for me.

        JComponent     title = ((BasicInternalFrameUI)myInternalFrame.getUI()).getNorthPane();
        for (int i = 0; i < title.getComponentCount(); i++) {
            JComponent component = (JComponent)title.getComponent(i);
            if(component instanceof JButton) {
                JButton button = ((JButton)component);
                if(button.getName() == null) continue;
                if(button.getName().endsWith("closeButton")) {
                    button.setIcon(myIcon);
                    button.setSelectedIcon(myIcon);
                    button.setPressedIcon(myIcon);
                }
                if(button.getName().endsWith("maximizeButton")) {
                    ...
                }
                if(button.getName().endsWith("iconifyButton")) {
                    ...
                }
            }
        }