[英]use JavaFx Application in swing project
I have to browse Html files in java windows application software . 我必须在Java Windows应用程序软件中浏览HTML文件。 For it i am using JEditorPane control but its not supporting some tags of HTML and formatting is disturbing in JEditorPane.
为此,我正在使用JEditorPane控件,但它不支持HTML的某些标签,并且JEditorPane中的格式受到干扰。 I have searched on net and net is suggesting me to use JavaFXApplication control for it .
我在网上搜索过,网上建议我对其使用JavaFXApplication控件。 In C# there is a control WebBrowser that displays the html file in the same format easily .
在C#中,有一个控件WebBrowser可以轻松地以相同格式显示html文件。 Is it possible in java too to display the html files with all supporting tags .
是否也可以在Java中显示带有所有支持标签的html文件。 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)
{
}
If I understand your question correctly, you are trying to view the HTML SOURCE and not trying to implement a web browser. 如果我正确理解了您的问题,则您正在尝试查看HTML SOURCE,而不是在尝试实现网络浏览器。
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 如果是这种情况,您可以使用JavaFX的HTML编辑器, 前提是您将Java 6与JavaFX配合使用,或者将Java 7(包括JavaFX)与JavaFX结合使用
Here's a short sample of using the javafx package using the JFXPanel and HTMLEditor : 这是使用JFXPanel和HTMLEditor使用javafx包的简短示例:
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();
}
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.