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? can you post some relevant code?
以上就是JTextArea font change is slow的详细内容,更多请关注web前端其它相关文章!