下面列出了怎么用javax.swing.text.html.CSS.Attribute的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* CSS with e.g. 'font-size: 75%' makes the HTML unreadable in the default JEditorPane
* @param key
* @param value
* @return
*/
private static String fixFontSize( Attribute key, String value ) {
if( "font-size".equals( key.toString() ) && null != value && value.endsWith( "%" ) ) {
String strPercentage = value.replace( "%", "");
int percentage = Integer.parseInt( strPercentage );
if( percentage < 100 ) {
value = "100%";
}
}
return value;
}
@Override
public void addCSSAttribute( MutableAttributeSet attr, Attribute key, String value ) {
value = fixFontSize( key, value );
super.addCSSAttribute( attr, key, value );
}
@Override
public boolean addCSSAttributeFromHTML( MutableAttributeSet attr, Attribute key, String value ) {
value = fixFontSize( key, value );
return super.addCSSAttributeFromHTML( attr, key, value );
}