I am trying to create a text editor using a JTextPane that outputs the text as HTML. I want to include the options to bold, color and align the text. I am having an issue with changing the color of a selection of text that is a mix of bold and not bold. For example, if I have the text in the editor "bold text not bold text" and I highlight both words and try to change the color of the text, it changes the color and makes all of the text bold, instead of leaving the second word not bold. So I'm not sure where this issue is coming from, if it has to do with setCharacterAttributes or if it's a problem with outputing the text as html. here is some of my code that makes the text bold:
MutableAttributeSet attrs = pane.getInputAttributes();
StyleConstants.setBold(attrs, bold);
pane.getStyledDocument().setCharacterAttributes(p.getSelectionStart(),len,attrs,false);
Here is an example of what the html output looks like before and after I change the color of the text. This is just whats inside of the body tags
Before: bold text not bold text
After change color to red: bold text not bold text
And it has something to do with whether or not the first word of the selection is bold. If I did the same example, but the 2nd part was bold and the first part was not bold, then it works fine. So it has something to do with when the beginning of the text selection is bold.