0

I have a JTextPane, I have created some styles:

Style assistant = addStyle("assistant", null);
StyleConstants.setForeground(assistant, Color.decode("#01AF07"));
Style user = addStyle("user", null);
StyleConstants.setForeground(user, Color.decode("#237D03"));
addStyle("text", null);

The format of the panel is:

Assistant> Text
User> Text

Where "Assistant>" and "User>" have styles "assistant" and "user" respectively. And "Text" has the style "text"

I have already made settings for my application where the user can change the font, I configured it and attached it to the method:

public void applyFont(Font generalFont) {
    StyleConstants.setFontSize(getStyle("assistant"), generalFont.getSize());
    StyleConstants.setFontSize(getStyle("text"), generalFont.getSize());
    StyleConstants.setFontSize(getStyle("user"), generalFont.getSize());

    StyleConstants.setFontFamily(getStyle("assistant"), generalFont.getFamily());
    StyleConstants.setFontFamily(getStyle("text"), generalFont.getFamily());
    StyleConstants.setFontFamily(getStyle("user"), generalFont.getFamily());

    StyleConstants.setItalic(getStyle("assistant"), generalFont.isItalic());
    StyleConstants.setItalic(getStyle("text"), generalFont.isItalic());
    StyleConstants.setItalic(getStyle("user"), generalFont.isItalic());

    StyleConstants.setBold(getStyle("assistant"), generalFont.isBold());
    StyleConstants.setBold(getStyle("text"), generalFont.isBold());
    StyleConstants.setBold(getStyle("user"), generalFont.isBold());
}

But my problem is that in the panel the style does not change, according to the new styles, only the text that was written after the change is changed. Tell me how to update according to style changes?

  • [How to Use Editor Panes and Text Panes](https://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html) – Abra Aug 02 '22 at 08:41
  • @Abra The fact is that I loaded the styles and it is displayed normally, only when I let's change the size of the style, the already existing text in the panel remains the same – Ashaley Aug 02 '22 at 08:47
  • 1
    Consider posting a [mcve] where you create a `JTextPane` and add it to a `JFrame` along with a `JButton` that, when you click it, makes the style changes described in your question.. – Abra Aug 02 '22 at 08:47

0 Answers0