Search code examples
javaswingjscrollpanejeditorpane

Java jScrollPane not displaying scollbars


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);
    }

}

Solution

  • scrollWeb.add(editorWeb);

    Don't add components to the scrollpane. Intead you add components to the viewport of the scrollpane:

    scrollWed.setViewportView( editorWeb );
    

    Or, when you create the scrollpane you can use:

    scrollWeb = new JScrollPane( editorWed );