This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!