views:

246

answers:

2

For some reason my HTML page is not appearing 100% on screen when it should, it looks like a timing issue to me. If I remove scrollpane and use just EditorPane it works ok.

What kind of code should I add below to force java applet screen to redraw/refresh and can I somehow wait until all images were really loaded ok? Currently images are drawn a bit after text is visible on GUI.
(the gray goes away and missing text appears when I minimize+maximize window.)

I use SynchronousHTMLEditorKit as m_editorPane.setEditorKitForContentType

private JEditorPane m_editorPane = new JTextPane();
private JScrollPane m_scrollPane = new JScrollPane();
....
JEditorPane.registerEditorKitForContentType( "text/html", "SynchronousHTMLEditorKit" );
m_editorPane.setEditorKitForContentType( "text/html", new SynchronousHTMLEditorKit() );
 m_editorPane.setPage(ResourceLoader.getURLforDataFile(file));
 m_scrollPane.getViewport().add(m_editorPane);
 m_scrollPane.validate();
 m_scrollPane.repaint(); <-- does not seem to solve this

add(m_scrollPane);
///    add(  m_editorPane) <-- this WORKS !!

SynchronousHTMLEditorKit is defined as:

public class SynchronousHTMLEditorKit extends HTMLEditorKit {
    public Document createDefaultDocument(){
        HTMLDocument doc = (HTMLDocument)(super.createDefaultDocument());
        doc.setAsynchronousLoadPriority(-1); //do synchronous load
        return doc;
    }
A: 

What happens if you don't use a SynchronousHTMLEditorKit? Your code works perfectly for me without it.

Michael Myers
its works pretty well without SynchronousHTMLEditorKit, but unfortunately sometimes IMAGES do not appear before I move a mouse a bit over the panel. any way to force image redrawing?
Tom
+1  A: 

Try moving the validate and repaint calls to the bottom, after the add, and call them on the container, not the scrollpane

add(m_scrollPane);
validate();
repaint();
Darren