Question

I am working on a Java Swing application (JDK 7). I have two JEditorPane instances on two different JFrames, that I need to synchronize. I know the hard way of force copying contents on a modified event is one way to do it. But, I was wondering if there is a smarter/easier way to do this. I tried to use the same JEditorPane instances on both the frames, but that did not work.

I believe a reference to the container panel is included in the JEditorPane instance, so the old container is erased when it is added to a new container. Can we create a new subclass of JEditorPane, that can accommodate two containers?

Have you tried something like this before?

Was it helpful?

Solution

Use 2 instances of JEditorPane. Set them the same EditorKit and then use Document from the first one in the second.

editorPane2.setDocument(editorPane1.getDocument());

Document is a model in fact and you can share the same model between 2 components.

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