-
- All Superinterfaces:
- Document
- All Known Implementing Classes:
- DefaultStyledDocument, HTMLDocument
public interface StyledDocument extends Document
Interface for a generic styled document.
-
-
Field Summary
-
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
-
-
Method Summary
Methods Modifier and Type Method and Description Style
addStyle(String nm, Style parent)
Adds a new style into the logical style hierarchy.Color
getBackground(AttributeSet attr)
Takes a set of attributes and turn it into a background color specification.Element
getCharacterElement(int pos)
Gets the element that represents the character that is at the given offset within the document.Font
getFont(AttributeSet attr)
Takes a set of attributes and turn it into a font specification.Color
getForeground(AttributeSet attr)
Takes a set of attributes and turn it into a foreground color specification.Style
getLogicalStyle(int p)
Gets a logical style for a given position in a paragraph.Element
getParagraphElement(int pos)
Gets the element that represents the paragraph that encloses the given offset within the document.Style
getStyle(String nm)
Fetches a named style previously added.void
removeStyle(String nm)
Removes a named style previously added to the document.void
setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)
Changes the content element attributes used for the given range of existing content in the document.void
setLogicalStyle(int pos, Style s)
Sets the logical style to use for the paragraph at the given position.void
setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace)
Sets paragraph attributes.-
Methods inherited from interface javax.swing.text.Document
addDocumentListener, addUndoableEditListener, createPosition, getDefaultRootElement, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, insertString, putProperty, remove, removeDocumentListener, removeUndoableEditListener, render
-
-
-
-
Method Detail
-
addStyle
Style addStyle(String nm, Style parent)
Adds a new style into the logical style hierarchy. Style attributes resolve from bottom up so an attribute specified in a child will override an attribute specified in the parent.- Parameters:
nm
- the name of the style (must be unique within the collection of named styles). The name may be null if the style is unnamed, but the caller is responsible for managing the reference returned as an unnamed style can't be fetched by name. An unnamed style may be useful for things like character attribute overrides such as found in a style run.parent
- the parent style. This may be null if unspecified attributes need not be resolved in some other style.- Returns:
- the style
-
removeStyle
void removeStyle(String nm)
Removes a named style previously added to the document.- Parameters:
nm
- the name of the style to remove
-
getStyle
Style getStyle(String nm)
Fetches a named style previously added.- Parameters:
nm
- the name of the style- Returns:
- the style
-
setCharacterAttributes
void setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)
Changes the content element attributes used for the given range of existing content in the document. All of the attributes defined in the given Attributes argument are applied to the given range. This method can be used to completely remove all content level attributes for the given range by giving an Attributes argument that has no attributes defined and setting replace to true.- Parameters:
offset
- the start of the change >= 0length
- the length of the change >= 0s
- the non-null attributes to change to. Any attributes defined will be applied to the text for the given range.replace
- indicates whether or not the previous attributes should be cleared before the new attributes as set. If true, the operation will replace the previous attributes entirely. If false, the new attributes will be merged with the previous attributes.
-
setParagraphAttributes
void setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace)
Sets paragraph attributes.- Parameters:
offset
- the start of the change >= 0length
- the length of the change >= 0s
- the non-null attributes to change to. Any attributes defined will be applied to the text for the given range.replace
- indicates whether or not the previous attributes should be cleared before the new attributes are set. If true, the operation will replace the previous attributes entirely. If false, the new attributes will be merged with the previous attributes.
-
setLogicalStyle
void setLogicalStyle(int pos, Style s)
Sets the logical style to use for the paragraph at the given position. If attributes aren't explicitly set for character and paragraph attributes they will resolve through the logical style assigned to the paragraph, which in turn may resolve through some hierarchy completely independent of the element hierarchy in the document.- Parameters:
pos
- the starting position >= 0s
- the style to set
-
getLogicalStyle
Style getLogicalStyle(int p)
Gets a logical style for a given position in a paragraph.- Parameters:
p
- the position >= 0- Returns:
- the style
-
getParagraphElement
Element getParagraphElement(int pos)
Gets the element that represents the paragraph that encloses the given offset within the document.- Parameters:
pos
- the offset >= 0- Returns:
- the element
-
getCharacterElement
Element getCharacterElement(int pos)
Gets the element that represents the character that is at the given offset within the document.- Parameters:
pos
- the offset >= 0- Returns:
- the element
-
getForeground
Color getForeground(AttributeSet attr)
Takes a set of attributes and turn it into a foreground color specification. This might be used to specify things like brighter, more hue, etc.- Parameters:
attr
- the set of attributes- Returns:
- the color
-
getBackground
Color getBackground(AttributeSet attr)
Takes a set of attributes and turn it into a background color specification. This might be used to specify things like brighter, more hue, etc.- Parameters:
attr
- the set of attributes- Returns:
- the color
-
getFont
Font getFont(AttributeSet attr)
Takes a set of attributes and turn it into a font specification. This can be used to turn things like family, style, size, etc into a font that is available on the system the document is currently being used on.- Parameters:
attr
- the set of attributes- Returns:
- the font
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/swing/text/styleddocument.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.