• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Unable to view a simple html page in JEditorPane.  RSS feed

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying this code pls correct it.but it gives this Exception and output
Output......
///////////////////////////////////////////////
text/plain
text/html
Exception in thread "main" java.net.MalformedURLException: no protocol: <html><b
ody><h1>W O W !.............</h1></body></html>
at java.net.URL.<init>(URL.java:579)
at java.net.URL.<init>(URL.java:476)
at java.net.URL.<init>(URL.java:425)
at javax.swing.JEditorPane.setPage(JEditorPane.java:774)
at JEditorPaneDemo.main(JEditorPaneDemo.java:17)
///////////////////////////////////////////////

Code....
///////////////////////////////////////////////
import javax.swing.*;
class JEditorPaneDemo
{
public static void main(String args[]) throws Exception
{
JFrame frm=new JFrame("EditorPane");
JEditorPane jdp=new JEditorPane();
String data="<html><body><h1>W O W !.............</h1></body></html>";
System.out.println(jdp.getContentType());
jdp.setContentType("text/html");
System.out.println(jdp.getContentType());
jdp.setPage(data);
frm.getContentPane().add(jdp);
frm.pack();
frm.setVisible(true);
}
}
///////////////////////////////////////////////
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rahul,
The problem is, that you are expecting setPage() to take a String and put the contents of that String into the JEditorPane. setPage(String url) expects the String to resolve into a properly formed URL and then attempts to load that resource over the network.
Hope this helps
Michael Morris
SCJP2
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The setPage() method requires a URL object or a String representation of a URL. You are using a String. Try the setText() method. It should work then. I corrected it below--I have not tested it.


Code....
///////////////////////////////////////////////
import javax.swing.*;
class JEditorPaneDemo
{
public static void main(String args[]) throws Exception
{
JFrame frm=new JFrame("EditorPane");
JEditorPane jdp=new JEditorPane();
String data="<html><body><h1>W O W !.............</h1></body></html>";
System.out.println(jdp.getContentType());
jdp.setContentType("text/html");
System.out.println(jdp.getContentType());
jdp.setText(data);
frm.getContentPane().add(jdp);
frm.pack();
frm.setVisible(true);
}
}
///////////////////////////////////////////////


HTH,
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!