Exception while painting icon

Hello,

Any idea why would I get this? It happened with me few times.

        at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
        at java.awt.image.BufferedImage.<init>(BufferedImage.java:321)
        at bibliothek.gui.dock.util.DockUtilities.disabledIcon(DockUtilities.java:521)
        at bibliothek.gui.dock.themes.basic.action.BasicButtonModel.getPaintIcon(BasicButtonModel.java:634)
        at bibliothek.gui.dock.themes.basic.action.BasicButtonModel.getPaintIcon(BasicButtonModel.java:602)
        at bibliothek.gui.dock.themes.basic.action.buttons.MiniButtonContent$ForwardIcon.paintIcon(MiniButtonContent.java:347)
        at bibliothek.gui.dock.util.DockUtilities.disabledIcon(DockUtilities.java:523)
        at bibliothek.gui.dock.util.swing.OrientedLabel.paintForeground(OrientedLabel.java:328)
        at bibliothek.gui.dock.util.BackgroundPanel.paintComponent(BackgroundPanel.java:119)
        at bibliothek.gui.dock.util.swing.OrientedLabel.paint(OrientedLabel.java:315)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at bibliothek.extension.gui.dock.theme.eclipse.RoundRectButton.doPaintForeground(RoundRectButton.java:245)
        at bibliothek.extension.gui.dock.theme.eclipse.RoundRectButton.paintComponent(RoundRectButton.java:171)
        at javax.swing.JComponent.paint(JComponent.java:1029)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at bibliothek.gui.dock.util.BackgroundPanel.paintChildren(BackgroundPanel.java:167)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at bibliothek.gui.dock.util.BackgroundPanel.paint(BackgroundPanel.java:109)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at bibliothek.gui.dock.util.BackgroundPanel.paintChildren(BackgroundPanel.java:167)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at bibliothek.gui.dock.util.BackgroundPanel.paint(BackgroundPanel.java:109)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at bibliothek.gui.dock.util.BackgroundPanel.paintChildren(BackgroundPanel.java:167)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at bibliothek.gui.dock.util.BackgroundPanel.paint(BackgroundPanel.java:109)
        at bibliothek.extension.gui.dock.theme.eclipse.displayer.NoTitleDisplayer.paint(NoTitleDisplayer.java:240)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at bibliothek.gui.dock.util.BackgroundPanel.paintChildren(BackgroundPanel.java:167)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at bibliothek.gui.dock.util.BackgroundPanel.paint(BackgroundPanel.java:109)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JViewport.paint(JViewport.java:747)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
        at javax.swing.JComponent.paintChildren(JComponent.java:862)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
        at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1491)
        at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1422)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1225)
        at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:786)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
        at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:694)
        at javax.swing.RepaintManager.access$700(RepaintManager.java:41)
        at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1636)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
        at java.awt.EventQueue.access$000(EventQueue.java:84)
        at java.awt.EventQueue$1.run(EventQueue.java:607)
        at java.awt.EventQueue$1.run(EventQueue.java:605)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)```

Thanks a lot,
Shant

Could it be, that your application uses an icon of size 0/0 for a button?

I don’t think so, because it seemed to happen randomly. I mean, usually, when I don’t get the Exception, the same screen is painted correctly.

Ok, I have to admit I never experienced this exception. I’ll add some code to prevent it from happening, but that does not solve the real bug.

Hm, what LookAndFeel do you use?
You use any custom icons? Perhaps some kind of icon that is not an ImageIcon?

I use Synthetica LookAndFeel.
Yes, I do use a custom implementation of Icon, which draws more than one image in its paintIcon method, to create the effect of a layered icon.

I understand it makes perfectly sense for the problem to come from my Icon implementation, but in that case wouldn’t the problem occur consistently on every run, for the same screen?

It could also be that the problem was caused by the icon of some action button which I don’t set myself, such as Detach, Maximize, etc. or a separator icon…

Just to remind you that, for now, I don’t have a severe problem, since the Exception appeared few times, but then it didn’t occur again so far.

Thanks,
Shant

The exception would only occur if some button is disabled, because in that case the framework tries to copy the icon and make it look gray. Maybe next time you see the exception you can look out for a disabled button, it would be interesting to know what icon it shows.

Looking at the code the only reason for the exception can be that “Icon.getIconWidth/Height” returns 0.

But after thinking a bit, and contradicting my previous post, I would say the real bug is the framework not handling the icon properly.

Great! I’m glad you already have an idea! :smiley:

I had saved a screenshot at the time I had the Exception, and indeed there was a disabled button that didn’t appear. I attached a comparison (as you can see, even the dockable was not totally painted due to the Exception). Sorry, there’s nothing really interesting: there’s just a white gap instead of the button.

Thanks a lot Beni,
Shant

You might want to try out this version. As far as my testing goes, it should prevent the exception.

Thank you Beni! I’ll let you know in case the problem reoccurs.