I added a WebPage to my JFrame when we press a button (webpage opens in same Frame). It works fine. But I would like to add a scrollPane to it, but when I add the JScrollPane jsp = new JScrollPane(jep);(jep = JEditorPane) the webpage just won't show up.

I will add more info to this page if needed.

Code (main part)

            JEditorPane jep = new JEditorPane();
            jep.setEditable(false);
            try {
                jep.setPage("xxxxxxxxxxxxx");
            } catch (IOException error) {
                jep.setContentType("text/html");
            }   
            jep.setBounds(100, 50, 150, 100);
            JScrollPane jsp = new JScrollPane(jep);
                            add(jsp)
                add(jep);

Thanks, ~3751_Creator

有帮助吗?

解决方案

The reason is this Line:

jep.setBounds(100, 50, 150, 100);

You have set the bounds for JEditorPane but now you have added that JEditorPane to the JScrollPane. So instead of setting bounds for JEditorPane you should have use setbounds for JScrollPane.


This all was about the reason for not showing up the JEditorPane. But Now here a serious suggestion for you: The use of setBounds are highly discouraged. You should use inbuilt layouts for aligning components in Swing. Java AWT and Swing has provided lot of useful layouts for such task . Look at A Visual Guide to Layout Managers to know about how to use these layouts.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top