Consider the code,
Question #1
StyledDocument doc=textPane.getStyledDocument();
SimpleAttributeSet attrib=new SimpleAttributeSet();
attrib.addAttribute(StyleConstants.CharacterConstants.Alignment,StyleConstants.ALIGN_RIGHT);
doc.insertString(0,"This is sample text",attrib);
Why am i not able to get the alignment? and why i am able to get it by doing this
doc.setParagraphAttributes(0,doc.getLength(),attrib,false);
Question #2
attrib.addAttribute(StyleConstants.ColorConstants.Background,Color.LIGHT_GRAY);
doc.setParagraphAttributes(0,doc.getLength(),attrib,false);
Why am i not able to get the background color? and why i am able to get it by doing this
doc.insertString(0,"This is sample text",attrib);
Question #3
When can i get both working together i.e. text with a background and right alignment except using this way,
doc.insertString(0,"This is sample text",attrib);
doc.setParagraphAttributes(0,doc.getLength(),attrib,false);