2

I've been developing a java desktop application for a while now, using Swing. The application is pretty big which makes isolating the issue difficult.

I've tried to make my application run with Java 8 but I am having the following error:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JProgressBar cannot be cast to javax.swing.JMenuItem
    at javax.swing.plaf.synth.SynthGraphicsUtils.paint(SynthGraphicsUtils.java:490)
    at javax.swing.plaf.synth.SynthMenuUI.paint(SynthMenuUI.java:280)
    at javax.swing.plaf.synth.SynthMenuUI.update(SynthMenuUI.java:245)
    at javax.swing.JComponent.paintComponent(JComponent.java:777)
    at javax.swing.JComponent.paint(JComponent.java:1053)
    at javax.swing.JComponent.paintChildren(JComponent.java:886)
    at javax.swing.JComponent.paint(JComponent.java:1062)
    at javax.swing.JComponent.paintChildren(JComponent.java:886)
    at javax.swing.JComponent.paint(JComponent.java:1062)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)
    at javax.swing.JComponent.paintChildren(JComponent.java:886)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5230)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1572)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1495)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1265)
    at javax.swing.JComponent.paint(JComponent.java:1039)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:79)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:116)
    at java.awt.Container.paint(Container.java:1973)
    at java.awt.Window.paint(Window.java:3901)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:835)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:807)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:807)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:782)
    at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:731)
    at javax.swing.RepaintManager.access$1300(RepaintManager.java:64)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1720)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.seaglasslookandfeel.ui.SeaGlassScrollBarUI$2 cannot be cast to javax.swing.JMenuItem
    at javax.swing.plaf.synth.SynthGraphicsUtils.paint(SynthGraphicsUtils.java:490)
    at javax.swing.plaf.synth.SynthMenuUI.paint(SynthMenuUI.java:280)
    at javax.swing.plaf.synth.SynthMenuUI.update(SynthMenuUI.java:245)
    at javax.swing.JComponent.paintComponent(JComponent.java:777)
    at javax.swing.JComponent.paint(JComponent.java:1053)
    at javax.swing.JComponent.paintChildren(JComponent.java:886)
    at javax.swing.JComponent.paint(JComponent.java:1062)
    at javax.swing.JComponent.paintChildren(JComponent.java:886)
    at javax.swing.JComponent.paint(JComponent.java:1062)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)
    at javax.swing.JComponent.paintChildren(JComponent.java:886)
    at javax.swing.JComponent.paint(JComponent.java:1062)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5223)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1572)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1495)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1265)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5171)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4982)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:824)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:807)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:807)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:782)
    at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:731)
    at javax.swing.RepaintManager.access$1300(RepaintManager.java:64)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1720)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

I get no such error using Java 7.

I am using seaglass LaF which does not seems to be in active development anymore. If I use another LaF, the application runs fine.

The seaglass-demo jar does not get the ClassCastException on Java 8 either.

EDIT:

Actually I do get ClassCastException with seaglass-demo.

Moving to a different LaF would be a really big pain and would probably not look as good, any idea what is causing the problem on Java 8 but not Java 7?

Edit:

I just tried on Mac OS using Java 8 and got the same exceptions.

Community
  • 1
  • 1
  • Since all of the stacktrace entries start with `java(x)`, there probably won't be anything you can do – msrd0 Sep 23 '14 at 16:41
  • From the stack trace, `javax.swing.JProgressBar cannot be cast to javax.swing.JMenuItem`, it seems that a brogress bas is in a menu? If so, does removing it from the menu help? – kajacx Sep 23 '14 at 16:47
  • @kajacx The OP wrote that it has worked in Java7, so that can't be the problem – msrd0 Sep 23 '14 at 16:52
  • And btw I just checked out the [seaglass project page](https://code.google.com/p/seaglass/), it says "This is based on Nimbus", so it actually won't make a big difference to switch to the Nimbus LaF – msrd0 Sep 23 '14 at 17:02
  • 1
    Tip: check that all Swing components are created and initialized on the event dispatch thread. Sometimes ClassCastExceptions happen if this is not the case, even with Java 6 or 7. These kind of thread-related errors do not happen consistently, maybe you would see it even with Java 7 on another computer. – lbalazscs Sep 23 '14 at 17:09
  • 1
    Do you do any weird stuff in your menus? It seems there shouldn't be any "SeaGlassScrollBarUI$2" installed in a JMenu component hierarchy. The fact that "it works with Java7" doesn't necessarily mean that there isn't something broken in the component hierarchy; only that it slipped through before. – Durandal Sep 23 '14 at 17:57
  • How can I verify that all Swing components are created and initialized on the event dispatch thread? – Guillaume Jimenez Sep 23 '14 at 18:18
  • I don't use scrollBar in my menu so not sure where that comes from. – Guillaume Jimenez Sep 23 '14 at 18:19
  • Note that this could occur because some classes are getting loaded twice by two different class loaders. – Hot Licks Sep 24 '14 at 00:47
  • @HotLicks can you give more details on what you mean? – Guillaume Jimenez Sep 24 '14 at 05:16
  • 2
    It seems that someone abused code meant to draw `JMenuItem` artifacts to draw artifacts of other components (e.g. to have the same border, background, etc.). It doesn’t need to be done by calling the paint code directly, setting a `MenuUI` on a component which isn’t a menu or manipulating the UIDefaults table may have the same effect. That works as long as the drawing code does not rely on the component being of the right type (i.e. never does a cast to its type). But since that is off specification, it might break when the drawing code changes what is exactly what happened here. – Holger Sep 24 '14 at 08:23

2 Answers2

2

Strictly, casting a JProgressBar as a JMenuItem is incorrect, as they are not directly related. They both have the same JComponent ancestor class, which is where the .paint() method that is in the stack trace is accessing.

If you can change the cast to JComponent, this should solve your problem. (although the stack trace seems to indicate only proprietary code)

However, why this has changed between 7 and 8 I do not know - perhaps there is a compiler option that is different in your setup?

simo.3792
  • 2,102
  • 1
  • 17
  • 29
0

Alright, after reading the comments it looks like seaglass laf won't make it to java 8 so I'll have to look for another laf I guess.

EDIT:

I was actually able to get the application running by compiling it with java 1.7 and running it with jre8 instead of jdk 1.8. Not sure why it would make a difference but it did.