Reputation: 1187
I have to browse Html files in java windows application software . For it i am using JEditorPane control but its not supporting some tags of HTML and formatting is disturbing in JEditorPane. I have searched on net and net is suggesting me to use JavaFXApplication control for it . In C# there is a control WebBrowser that displays the html file in the same format easily . Is it possible in java too to display the html files with all supporting tags . Can you suggest me the control or something wrong in my code.I am using the following code.
try
{
File htmlfile= new File("path of the html file");
JEditorPane htmlPane= new JEditorPane();
htmlPane.setEditable(false);
htmlPane.setContentType("text/html");
htmlPane.setPage(htmlfile.toURI().toURL());
JScrollPane jsp= new JScrollPane(htmlPane);
add(jsp);
}
catch(Exception ex)
{
}
Upvotes: 0
Views: 1286
Reputation: 1806
If I understand your question correctly, you are trying to view the HTML SOURCE and not trying to implement a web browser.
If that's the case you can use JavaFX's HTML editor assuming you are using Java 6 with JavaFX OR Java 7 which includes JavaFX
Here's a short sample of using the javafx package using the JFXPanel and HTMLEditor:
public class JavaFXDemo {
private static void initAndShowGUI() {
JFrame frame = new JFrame("HTML Editor");
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setSize(600, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Platform.runLater(new Runnable() {
@Override
public void run() {
final HTMLEditor htmlEditor = new HTMLEditor();
Scene scene = new Scene(htmlEditor);
fxPanel.setScene(scene);
}
});
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initAndShowGUI();
}
});
}
}
Upvotes: 1