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