- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to display a webpage in JEditorPane
Use the setPage() method of the JEditorPane to display a webpage:
JEditorPane editorPane = new JEditorPane(); editorPane.setPage("https://www.tutorialspoint.com");
The following is an example to display a webpage in JEditorPane:
Example
import java.io.IOException; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo { public static void main(String[] args) { JEditorPane editorPane = new JEditorPane(); try { editorPane.setPage("https://www.tutorialspoint.com"); } catch (IOException e) { editorPane.setContentType("text/html"); editorPane.setText("<html>Connection issues!</html>"); } JScrollPane pane = new JScrollPane(editorPane); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(pane); frame.setSize(500, 300); frame.setVisible(true); } }
Output
Advertisements