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?