@ -256,8 +256,11 @@ public class RichTextToolBar extends BasicPane{
@Override
public void actionPerformed ( ActionEvent e ) {
boolean isSub = RichTextToolBar . this . subPane . isSelected ( ) ;
// 调用setCharacterAttributes函数设置文本区选择文本的字体
MutableAttributeSet attr = new SimpleAttributeSet ( ) ;
if ( ! isSub & & RichTextToolBar . this . superPane . isSelected ( ) ) {
StyleConstants . setSuperscript ( attr , false ) ;
}
// 调用setCharacterAttributes函数设置文本区选择文本的字体
StyleConstants . setSubscript ( attr , ! isSub ) ;
setCharacterAttributes ( RichTextToolBar . this . textPane , attr , false ) ;
}
@ -269,6 +272,9 @@ public class RichTextToolBar extends BasicPane{
boolean isSuper = RichTextToolBar . this . superPane . isSelected ( ) ;
// 调用setCharacterAttributes函数设置文本区选择文本的字体
MutableAttributeSet attr = new SimpleAttributeSet ( ) ;
if ( ! isSuper & & RichTextToolBar . this . subPane . isSelected ( ) ) {
StyleConstants . setSubscript ( attr , false ) ;
}
StyleConstants . setSuperscript ( attr , ! isSuper ) ;
setCharacterAttributes ( RichTextToolBar . this . textPane , attr , false ) ;
}
@ -402,7 +408,7 @@ public class RichTextToolBar extends BasicPane{
bold . setSelected ( isBold ) ;
italic . setSelected ( isItalic ) ;
underline . setSelected ( isUnderline ) ;
subPane . setSelected ( isSubscript ) ;
subPane . setSelected ( isSuperscript ? false : isSu bscript ) ;
superPane . setSelected ( isSuperscript ) ;
//为什么字体名称, 大小, 颜色, 不需要去判断是否全相同呢
//因为如果全相同, 则设置为第一个字符的样式, 如果不全相同, 那么默认也设置成第一个字符的样式.