This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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,
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!