【发布时间】:2014-01-06 04:27:00
【问题描述】:
如何改变某个起点的字体?
我有一个按钮,在某个点切换字体。
例子:
somtext |
按下按钮
sometext 粗体文本|
所以我释放了事件键,但我可以看到不断变化的字体释放键
这是关键释放事件
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());
}
}
但我明白了
第一个
结局一个
更新不是实时的还有另一种方法:
【问题讨论】:
-
如果您没有很快得到合适的答案,请考虑创建并发布sscce。
标签: java swing jtextpane caret