1

由于某种原因,我的 HTML 页面没有 100% 显示在屏幕上,这对我来说似乎是一个时间问题。如果我删除滚动窗格并仅使用 EditorPane 就可以了。

我应该在下面添加什么样的代码来强制 Java 小程序屏幕重绘/刷新,我可以以某种方式等到所有图像都真正加载好了吗?目前,在 GUI 上显示文本后会稍微绘制图像。
(当我最小化+最大化窗口时,灰色消失并出现丢失的文本。)

我使用 SynchronousHTMLEditorKit 作为 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定义为:

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

2 回答 2

1

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();
于 2009-04-21T13:10:29.467 回答
0

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

于 2009-04-16T14:05:46.547 回答