如何更改某個起點的字體?JTextPane更改某個起點的字體
我有一個按鈕,在某個點上切換字體。
例如:
somtext |
按下按鈕
sometext boldedtext |
所以我做了事件鍵釋放,但我可以看到改變字體的不斷釋放鍵
這關鍵公佈事件
private void textoKeyReleased(javax.swing.event.CaretEvent evt) {
int end = texto.getSelectionEnd();
StyledDocument doc = texto.getStyledDocument();
Style style = texto.getStyle("negra");
if (car==1)
{
StyleConstants.setBold(style, true);
doc.setCharacterAttributes(end-1,end, style, false);
texto.requestFocus();
texto.moveCaretPosition(doc.getLength());
}
if(car==0)
{
StyleConstants.setBold(style, false);
doc.setCharacterAttributes(end-1 ,end, style, false);
texto.requestFocus();
texto.moveCaretPosition(doc.getLength());
}
}
但我看到
第一個
壓軸a
更新不是實時還有另一種方法:
如果您很快就沒有得到體面的答案,請考慮創建併發布[sscce](http://sscce.org)。 –