Search code examples
javajtextpane

JTextPane AttributeSet


1 - First, can anyone explain me the difference between the following methods inside class JTextPane because i compile an example and they gave me always the same result :

  • setCharacterAttributes(AttributeSet attr, boolean replace)
  • setParagraphAttributes(AttributeSet attr, boolean replace)
  • setLogicalStyle(Style s)

2 - Second, What is the difference between the following methods (always inside class JTextPane) :

  • getInputAttributes()
  • getLogicalStyle()
  • getStyle(String nm)

It would be great if someone could give me an example which show the real use of all those methods, because their official documentations are not well explained.


Solution

    1. setCharacterAttributes: This is things like font and text color
    2. setParagraphAttributes: This should be used to set things like line spacing... See if you set the line spacing attributes, it shouldn't work with setCharacterAttributes
    3. setLogicalStyle: This will use the style type given. This has the same effect as setParagraphAttributes, but the style is from a logical style from the StyledDocument (check out the API for StyledDocument - addStyle)... the concept is like "Header 1" "Header 2" in word

    4. getInputAttributes: gets the attributes currently associated with where the cursor is in the JTextPane

    5. getLogicalStyle: get the local style (if any) that's been set where the cursor is
    6. getStyle(...): This will get a logical style from the StyledDocument