Skip to main content

JXEditorPane : class cast exception

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
gypaete33
Offline
Joined: 2011-01-13

Hi,
I am using the JXEditorPane (swingx 1.6.1) to edit plain text and to view HTLM source file.
When I am switching from HTML to plain text, I have got an exception :
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.text.PlainDocument cannot be cast to javax.swing.text.StyledDocument
at org.jdesktop.swingx.JXEditorPane$CaretHandler.caretUpdate(JXEditorPane.java:804)
at javax.swing.text.JTextComponent.fireCaretUpdate(JTextComponent.java:391)
at javax.swing.text.JTextComponent$MutableCaretEvent.fire(JTextComponent.java:4389)
at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(JTextComponent.java:4411)
at javax.swing.text.DefaultCaret.fireStateChanged(DefaultCaret.java:782)
at javax.swing.text.DefaultCaret.changeCaretPosition(DefaultCaret.java:1257)
at javax.swing.text.DefaultCaret.handleSetDot(DefaultCaret.java:1153)
at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:1134)
at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:1031)
at javax.swing.text.DefaultCaret$Handler.propertyChange(DefaultCaret.java:1829)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
at java.awt.Component.firePropertyChange(Component.java:7961)
at javax.swing.text.JTextComponent.setDocument(JTextComponent.java:437)
at javax.swing.JEditorPane.setEditorKit(JEditorPane.java:1097)
at org.jdesktop.swingx.JXEditorPane.setEditorKit(JXEditorPane.java:271)
Here is a sample code :
// switch to HTML :
...
saveEdKit = jXEditorPane1.getEditorKit();
jXEditorPane1.setEditable(false);
jXEditorPane1.setPage(new File(filename).toURI().toURL());
....
// switch to plain text :
...
jXEditorPane1.setEditorKit(saveEdKit);
jXEditorPane1.setEditable(true);
...
Am I doing right ?
Is there a workaround ?
Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kleopatra
Offline
Joined: 2003-06-11

to spell out Karl's implication: please file an issue in the SwingX issue tracker, so we don't forget to look into it :-)
Thanks
Jeanette

kschaefe
Offline
Joined: 2006-06-08

You've found a bug. We never uninstalled the CaretHandler when the new editor kit is not a StyledEditorKit.