i have this code to render a locally saved html file onto a jframe. i have the following problems with how the html was rendered:
1. the texts of the 'webpage' do not wrap;
2. in order to solve my problem in 1. above, i added a JScrollPane, problem is, the scrollbars do not appear.
any help is appreciated. thanks.
i have the code below:
(main method -TryJEditor.java)
(and the class - TryHtml.java)
import java.awt.*; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import javax.swing.*; public class TryHtml extends JFrame { private JEditorPane HtmlPane; private JPanel pane; private JScrollPane scroller; private String url = "file:///D:\\Java Exercise Programs\\TryJEditor\\myhtml.htm"; public TryHtml() { super("title"); FlowLayout fl = new FlowLayout(FlowLayout.LEFT); setLayout(fl); pane = new JPanel(); try { pane = new JPanel(); HtmlPane= new JEditorPane(url); HtmlPane.setContentType("text/html"); HtmlPane.setEditable(false); HtmlPane.setSize(500, 250); scroller = new JScrollPane(HtmlPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); } catch (IOException e) { e.printStackTrace(); } pane.add(scroller); add(pane); pack(); } }