Question

We've been struggling here at the office with a seemingly unsolvable bug in one of our (massive) applets, this one being a Java simulation of MS Word, for exam purposes. The exception seems to stem from swing itself, and I'm not sure how I would go about solving it. Here's what happens:

The applet loads with a loading screen till 100%. After this, the components are all displayed in a broken way as if some of their paint methods are not being called correctly, hovering the cursor over some buttons etc. does make them flash/display for a while. And an exception is printed to the console every second or so. (See below) This bug does NOT occur within Eclipse, only in the browser.

Summary: Applet components all get built without exceptions, but on every "paint" call of a some component (I assume), it visually bugs out and the following is printed every second:

Exception in thread "AWT-EventQueue-11" java.lang.ClassCastException: javax.swing.JLabel cannot be cast to javax.swing.text.JTextComponent
 at javax.swing.text.html.EditableView.paint(Unknown Source)
 at javax.swing.text.BoxView.paintChild(Unknown Source)
 at javax.swing.text.BoxView.paint(Unknown Source)
 at javax.swing.text.BoxView.paintChild(Unknown Source)
 at javax.swing.text.BoxView.paint(Unknown Source)
 at javax.swing.text.ParagraphView.paint(Unknown Source)
 at javax.swing.text.html.ParagraphView.paint(Unknown Source)
 at javax.swing.text.BoxView.paintChild(Unknown Source)
 at javax.swing.text.BoxView.paint(Unknown Source)
 at javax.swing.text.html.BlockView.paint(Unknown Source)
 at javax.swing.text.BoxView.paintChild(Unknown Source)
 at javax.swing.text.BoxView.paint(Unknown Source)
 at javax.swing.text.html.BlockView.paint(Unknown Source)
 at javax.swing.plaf.basic.BasicHTML$Renderer.paint(Unknown Source)
 at javax.swing.plaf.basic.BasicLabelUI.paint(Unknown Source)
 at javax.swing.plaf.ComponentUI.update(Unknown Source)
 at javax.swing.JComponent.paintComponent(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JLayeredPane.paint(Unknown Source)
 at javax.swing.JComponent.paintToOffscreen(Unknown Source)
 at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
 at javax.swing.RepaintManager.paint(Unknown Source)
 at javax.swing.JComponent._paintImmediately(Unknown Source)
 at javax.swing.JComponent.paintImmediately(Unknown Source)
 at javax.swing.RepaintManager$3.run(Unknown Source)
 at javax.swing.RepaintManager$3.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
 at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
 at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
 at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
 at javax.swing.RepaintManager.access$1000(Unknown Source)
 at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
 at java.awt.event.InvocationEvent.dispatch(Unknown Source)
 at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
 at java.awt.EventQueue.access$200(Unknown Source)
 at java.awt.EventQueue$3.run(Unknown Source)
 at java.awt.EventQueue$3.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)

Help would be greatly appreciated, as this is driving me nuts, I can't seem to find what triggers this, as the code is from a previous developer, and an utter mess. I have tried different JDK versions.

Thanx.

Was it helpful?

Solution 2

Found a fix to my problem. The target Java version was wrong. In the build.xml file, there were the following lines:

<property name="target" value="1.5" />
<property name="source" value="1.5" />

Changed those to 1.7, and voila! This seems to have been a Swing bug that has been fixed in the newer versions of Java.

OTHER TIPS

java.lang.ClassCastException: javax.swing.JLabel cannot be cast to javax.swing.text.JTextComponent

  • see components tree for JTextComponents, there isn't JLabel, JLabel isn't member of JTextComponents

  • safest could be to test if (Xxx instanceof JTextComponent) before any casting

I've noticed that this problem can occur when a JLabel with tags around the content contains nested tags. The solution is to escape the angle brackets on the

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top