I have JEditorPane (communicationView) in my Swing application, and sometimes I need scroll it to the bottom. Scrolling is done by setting caret position to the document end.
private void setCommunicationViewCaretPosition(){
communicationView.setCaretPosition(communicationView.getDocument().getLength());
}
This usually works, but after a while following exception gets thrown:
Exception in thread "Thread-6" java.lang.IllegalStateException: cannot open system clipboard
at sun.awt.windows.WClipboard.openClipboard(Native Method)
at sun.awt.datatransfer.SunClipboard.getClipboardFormatsOpenClose(SunClipboard.java:332)
at sun.awt.datatransfer.SunClipboard.isDataFlavorAvailable(SunClipboard.java:192)
at org.jdesktop.application.TextActions.updateTextActions(TextActions.java:132)
at org.jdesktop.application.TextActions.access$400(TextActions.java:47)
at org.jdesktop.application.TextActions$TextComponentCaretListener.caretUpdate(TextActions.java:115)
at javax.swing.text.JTextComponent.fireCaretUpdate(JTextComponent.java:407)
at javax.swing.text.JTextComponent$MutableCaretEvent.fire(JTextComponent.java:4417)
at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(JTextComponent.java:4439)
at javax.swing.text.DefaultCaret.fireStateChanged(DefaultCaret.java:802)
at javax.swing.text.DefaultCaret.changeCaretPosition(DefaultCaret.java:1277)
at javax.swing.text.DefaultCaret.handleSetDot(DefaultCaret.java:1173)
at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:1154)
at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:1051)
at javax.swing.text.JTextComponent.setCaretPosition(JTextComponent.java:1680)
at aau.application.ApplicationView.setCommunicationViewCaretPosition(ApplicationView.java:643)
I can't figure out why is this happening, or what setting caret position has to do with system clipboard.
Setting caret position seems to be the best way to scroll down the view but any other method would solve my problem.
To access the clipboard:
Create a class file with this text
The code above is accessible with this functions:
Create a new clipboard editor:
setData function:
getData function: