Java examples for Swing:Swing HTML
Set a Attribute in the Swing HTMLDocument structure.
//package com.java2s; import javax.swing.text.Element; import javax.swing.text.MutableAttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.html.HTML.Attribute; import javax.swing.text.html.HTMLDocument; public class Main { /**/*from w w w. j a va 2s . c o m*/ * Set a Attribute in the HTMLDocument structure. * * @param element * Element which contains the attribute. * @param attr * Attribute to alter. * @param value * Value of the attribute. */ public static void setAttribute(Element element, Attribute attr, Object value) { HTMLDocument doc = (HTMLDocument) element.getDocument(); setAttribute(doc, element.getStartOffset(), element.getEndOffset(), attr, value); } /** * Set a Attribute in the HTMLDocument structure. * * @param doc * HTMLDocument. * @param startOffset * Offset from the beginning of the document to the start of the * attribute in the HTML content. * @param endOffset * Offset from the beginning of the document to the end of the * attribute in the HTML content. * @param attr * Attribute to alter. * @param value * Value of the attribute. */ public static void setAttribute(HTMLDocument doc, int startOffset, int endOffset, Attribute attr, Object value) { MutableAttributeSet attributeSet = new SimpleAttributeSet(); attributeSet.addAttribute(attr, value); doc.setCharacterAttributes(startOffset, endOffset - startOffset, attributeSet, false); } }