本文整理汇总了Java中javax.swing.text.StyleConstants.isSubscript方法的典型用法代码示例。如果您正苦于以下问题:Java StyleConstants.isSubscript方法的具体用法?Java StyleConstants.isSubscript怎么用?Java StyleConstants.isSubscript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleConstants
的用法示例。
在下文中一共展示了StyleConstants.isSubscript方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributeSetFont
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/**
* Gets the font from an attribute set. This is
* implemented to try and fetch a cached font
* for the given AttributeSet, and if that fails
* the font features are resolved and the
* font is fetched from the low-level font cache.
* Font's are cached in the StyleSheet of a document
*
* @param attr the attribute set
* @return the font
*/
private Font getAttributeSetFont(AttributeSet attr) {
// PENDING(prinz) add cache behavior
int style = Font.PLAIN;
if (StyleConstants.isBold(attr)) {
style |= Font.BOLD;
}
if (StyleConstants.isItalic(attr)) {
style |= Font.ITALIC;
}
String family = StyleConstants.getFontFamily(attr);
int size = StyleConstants.getFontSize(attr);
/**
* if either superscript or subscript is
* is set, we need to reduce the font size
* by 2.
*/
if (StyleConstants.isSuperscript(attr) ||
StyleConstants.isSubscript(attr)) {
size -= 2;
}
// fonts are cached in the StyleSheet so use that
return doc.getStyleSheet().getFont(family, style, size);
}
示例2: actionPerformed
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e){
JEditorPane editor = getEditor(e);
if (editor != null) {
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean strike = (StyleConstants.isSubscript(attr)) ? false : true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setSubscript(sas, strike);
setCharacterAttributes(editor, sas, false);
}
}