Style ShareStyleContext

JTextPane c1 = new JTextPane();
JTextPane c2 = new JTextPane();

// Create new styled documents with the same style context
StyleContext styleContext = new StyleContext();
c1.setDocument(new DefaultStyledDocument(styleContext));
c2.setDocument(new DefaultStyledDocument(styleContext));

// Create a new style with one text pane
Style style = c1.addStyle("style name", null);
StyleConstants.setForeground(style, Color.red);

// Modify an existing style using the other text pane
style = c2.getStyle("style name");
StyleConstants.setBold(style, true);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.