JTextArea字体变化缓慢
我对 JTextArea 控件有一个奇怪的问题:
当我调出 JTextArea 时,一切都很好,我输入的任何内容都会立即显示。 然而,一旦我将 FontSizeAction
发送到我的 EditorKit
(本例中为 RTFEditorKit,但我使用哪个似乎并不重要),就会出现延迟,从 1 到几个几秒钟,发生了。
有趣的是,延迟仅在您键入内容后发生,即更改字体,然后什么也不做,然后键入,与立即键入没有区别。 延迟是一样的。 我可以看到,在 FontSizeAction 之后输入第一个字母后,分配量增加了几兆。
我在应用程序上使用了分析器,并且我自己的应用程序中似乎没有任何问题。
我的代码:
private void updateFont(MainModelManager model) {
(new RTFEditorKit.FontSizeAction("font-size-" + model.getFontSize(),
model.getFontSize())).actionPerformed(
new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null) );
(new RTFEditorKit.FontFamilyAction("font-family-" + model.getFontFamily(), model.getFontFamily())).actionPerformed(
new ActionEvent(this, ActionEvent.ACTION_PERFORMED, model.getFontFamily()) );
}
这是主模型容器声明的一部分:
public class MainModelManager extends Observable {
DefaultStyledDocument doc;
int fontSize = 12;
String fontType = "Helvetica";
StyleContext sc;
Caret editorCaret;
boolean editorFrameIsResizable;
//...
}
更新:
我认为我已经将问题范围缩小到了 FontFamilyAction,因为如果我将其注释掉延迟消失了,我仍然可以毫无问题地更改字体大小。 也许这与加载字体有关?
I have a curious problem with the JTextArea control:
When I bring up my JTextArea
everything is fine and whatever I type shows up without delay. However as soon as I send a FontSizeAction
to my EditorKit
(RTFEditorKit in this case, but it does not seem to matter which I use), a delay, from 1 - several seconds, happens.
Interestingly the delay only happens after you type something, that is a font change followed by doing nothing and then typing, makes no difference from just typing immediately. The delay is the same. I can see that right after typing the first letter after a FontSizeAction, allocation increases with a couple of megs.
I have used a profiler on the application and there's nothing in my own app that seems to be the problem.
My code:
private void updateFont(MainModelManager model) {
(new RTFEditorKit.FontSizeAction("font-size-" + model.getFontSize(),
model.getFontSize())).actionPerformed(
new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null) );
(new RTFEditorKit.FontFamilyAction("font-family-" + model.getFontFamily(), model.getFontFamily())).actionPerformed(
new ActionEvent(this, ActionEvent.ACTION_PERFORMED, model.getFontFamily()) );
}
This is part of the declaration of the main model container:
public class MainModelManager extends Observable {
DefaultStyledDocument doc;
int fontSize = 12;
String fontType = "Helvetica";
StyleContext sc;
Caret editorCaret;
boolean editorFrameIsResizable;
//...
}
UPDATE:
I think I have narrowed to problem down to the FontFamilyAction because, if I comment it out the delay disappears and I can still change the font size without a problem. Maybe this has something to do with loading fonts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论