Results 1 to 7 of 7
Thread: displaying html in java (SWING)
- 12-08-2012, 03:15 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
displaying html in java (SWING)
I am working on a project of sorts to load HTML files from a server and display them in swing.
Error:Java Code:import java.io.*; import java.net.*; import java.util.regex.*; import javax.swing.*; public class webloader { public static void loadcode(){ URL url = null; try { url = new URL("web"+File.separator+web.url+File.separator+"index.html"); } catch (MalformedURLException e) { e.printStackTrace(); } URLConnection con = null; try { con = url.openConnection(); } catch (IOException e) { e.printStackTrace(); } Pattern p = Pattern.compile("text/html;\\s+charset=([^\\s]+)\\s*"); Matcher m = p.matcher(con.getContentType()); String charset = m.matches() ? m.group(1) : "ISO-8859-1"; Reader r = null; try { r = new InputStreamReader(con.getInputStream(), charset); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } StringBuilder buf = new StringBuilder(); while (true) { int ch = 0; try { ch = r.read(); } catch (IOException e) { e.printStackTrace(); } if (ch < 0) break; buf.append((char) ch); } String str = buf.toString(); JFrame mainframe = new JFrame(web.url); mainframe.setSize(800, 750); mainframe.setResizable(false); JPanel website = new JPanel(); JLabel webcontent = new JLabel(str); website.add(webcontent); mainframe.add(website); mainframe.setVisible(true); } }
#5498427 - Pastie
PS. I am quite new to java, so if I seem to be stupid or not know what I am doing, that's because I am.
-
Re: displaying html in java (SWING)
I've seen this question elsewhere -- have you cross-posted this question on a different site? If so, please notify us with links to the other site.
- 12-08-2012, 03:20 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
Re: displaying html in java (SWING)
Displaying HTML in swing (JAVA) - Stack Overflow
I posted it here, got no where.
- 12-10-2012, 11:11 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: displaying html in java (SWING)
on line 11.Java Code:web.url
You have no 'web' variable.
This code does not compile, so trying to run it is a bit pointless (which is sort of what that error is telling you).
Also, I would recommend actually posting the stack trace and error along with your post.
Many people won't bother going to links.Please do not ask for code as refusal often offends.
- 12-31-2012, 12:50 PM #5
Member
- Join Date
- Sep 2012
- Location
- Guntur, India
- Posts
- 27
- Rep Power
- 0
Re: displaying html in java (SWING)
You can simply do it with appending <html> tag at the start and end positions.
[Blog spam removed]Last edited by DarrylBurke; 12-31-2012 at 04:25 PM.
- 12-31-2012, 01:46 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: displaying html in java (SWING)
That is not the solution to the OPs problem in the slightest.
Please do not ask for code as refusal often offends.
- 12-31-2012, 04:28 PM #7
Similar Threads
-
Java swing - HtmlEditor not displaying '<' symbol....
By anantth in forum AWT / SwingReplies: 0Last Post: 07-26-2011, 11:50 AM -
How to embed java swing into a html
By tomkonikkara in forum NetBeansReplies: 2Last Post: 07-11-2011, 08:10 AM -
Problem with displaying an image in Java Swing
By BackInSoftware in forum Advanced JavaReplies: 10Last Post: 01-11-2011, 06:56 PM -
Java Programmers needed ASAP Tucson, AZ Swing, Maven, HTML, XML, SQL
By pbracey in forum Jobs OfferedReplies: 0Last Post: 07-19-2010, 10:25 PM -
Displaying a Java List in Html:select tag
By ramitmehra123 in forum New To JavaReplies: 0Last Post: 02-07-2008, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks