tags:

views:

279

answers:

0

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.

Thanks in advance.

UPDATE: Here is some 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
{
    private DefaultStyledDocument doc;
    private int fontSize = 12;
    private String fontType = "Helvetica";
    private StyleContext sc; 
    private Caret editorCaret;
    private 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?