在swing应用程序中显示一个网页

时间:2023-01-28 15:15:01

I would like to display a webpage inside a java swing application. Similar to a when using HTML, but in java Swing. Is this possible and if so, how?

我想在java swing应用程序中显示一个网页。类似于使用HTML时,但在Java Swing中。这是可能的,如果是的话,怎么样?

2 个解决方案

#1


20  

Use a JEditorPane:

使用JEditorPane:

JEditorPane jep = new JEditorPane();
jep.setEditable(false);   

try {
  jep.setPage("http://www.yoursite.com");
}catch (IOException e) {
  jep.setContentType("text/html");
  jep.setText("<html>Could not load</html>");
} 

JScrollPane scrollPane = new JScrollPane(jep);     
JFrame f = new JFrame("Test HTML");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(scrollPane);
f.setPreferredSize(new Dimension(800,600));
f.setVisible(true);

#2


6  

You might want to look at http://java.dzone.com/articles/web-browser-your-java-swing.

您可能需要查看http://java.dzone.com/articles/web-browser-your-java-swing。

JxBrowser lets you display any webpage,by embedding a browser into your swing application.

JxBrowser允许您通过将浏览器嵌入到swing应用程序中来显示任何网页。

#1


20  

Use a JEditorPane:

使用JEditorPane:

JEditorPane jep = new JEditorPane();
jep.setEditable(false);   

try {
  jep.setPage("http://www.yoursite.com");
}catch (IOException e) {
  jep.setContentType("text/html");
  jep.setText("<html>Could not load</html>");
} 

JScrollPane scrollPane = new JScrollPane(jep);     
JFrame f = new JFrame("Test HTML");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(scrollPane);
f.setPreferredSize(new Dimension(800,600));
f.setVisible(true);

#2


6  

You might want to look at http://java.dzone.com/articles/web-browser-your-java-swing.

您可能需要查看http://java.dzone.com/articles/web-browser-your-java-swing。

JxBrowser lets you display any webpage,by embedding a browser into your swing application.

JxBrowser允许您通过将浏览器嵌入到swing应用程序中来显示任何网页。

相关文章