0

I'm trying to get scrollbars working on my scroll pane. Originally my pane had been just a editor pane that loaded a webpage. However, I did research and found out you can't add scrollbars natively to that kind of jSwing element. So, I made a jScrollPane and added a jEditorPane to it. Everything works great except I can't figure out why there are no scroll bars appearing and the pane is completely unscrollable. Any help is greatly appreciated, thank you.

public Main() {
    initComponents();
    scrollWeb.add(editorWeb);
    editorWeb.setEditable(false);
    editorWeb.setSize(scrollWeb.getWidth(), scrollWeb.getHeight());
    try {
        editorWeb.setPage("http://www.futureretrogaming.tk/news.html");
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

}
4

2 回答 2

3

scrollWeb.add(editorWeb);

不要将组件添加到滚动窗格。Intead 您将组件添加到滚动窗格的视口:

scrollWed.setViewportView( editorWeb );

或者,当您创建滚动窗格时,您可以使用:

scrollWeb = new JScrollPane( editorWed );
于 2013-10-30T17:07:25.933 回答
2

如果您将 JScrollPane 的视口所持有的组件的大小强制为与 JScrollPane 相同的大小,则不会滚动:

editorWeb.setSize(scrollWeb.getWidth(), scrollWeb.getHeight());

只是不要这样做,因为这会将 JEditorPane 的大小限制为 JScollPane 的大小并且不会更大,因此它永远不会扩展。而是让 editorWeb 根据其内容变大。

于 2013-10-30T16:58:13.600 回答