k_suchdeva
asked on
Displaying HTML content in a JTextArea
How to program in Swing to display HTML style content.
I mean will it work ??
JTextArea area=new JTextArea();
area.setText("<b>Hi hoooo ho hooo</b>");
I have heard that it is possible in Swing but do not know how to do it and the above approach does not work.
So basically I want to display some HTML style content in a JTextarea.
Thanx and Regards
Khem
I mean will it work ??
JTextArea area=new JTextArea();
area.setText("<b>Hi hoooo ho hooo</b>");
I have heard that it is possible in Swing but do not know how to do it and the above approach does not work.
So basically I want to display some HTML style content in a JTextarea.
Thanx and Regards
Khem
JeditorPane pane = new JEditorPane("http://abc.com/some.html");
pane.setEditable(false);
pane.setEditable(false);
Or:
pane.setContentType("text/ html");
pane.setText("<html><body> <b>abc</b> </body></h tml.");
pane.setContentType("text/
pane.setText("<html><body>
ASKER
I have found it i can do it using JLabel from Sun Tutorial on JLabel.
Yep, JLabel also has (limited) html support.
You must use JEditorPane or JTextPane for displaying html content setted with the HTMLEditorKit and HTMLDocument as defaults. after that you have there a method called setPage(URL) and of course setText()
Didn't I just say that :)
Sorry, I have a "very good" connection here. Sorry again.
ASKER
Ovi and Objects
Please write some code displaying a full HTML page with images using the JEditorPane etc.
Please write some code displaying a full HTML page with images using the JEditorPane etc.
I already did :)
JeditorPane pane = new JEditorPane("http://abc.com/some.html");
pane.setEditable(false);
JeditorPane pane = new JEditorPane("http://abc.com/some.html");
pane.setEditable(false);
import java.awt.*;
import javax.swing.*;
public class TestHTML {
public static void main(String args[]) {
JEditorPane pane = null;
JFrame f = new JFrame();
f.setSize(400, 400);
f.setLocation(150, 100);
f.getContentPane().setLayo ut(new BorderLayout());
try {
pane = new JEditorPane("https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20152577");
} catch(Exception e) {}
f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER);
f.setVisible(true);
}
}
You must wait a little until the page is loaded.
import javax.swing.*;
public class TestHTML {
public static void main(String args[]) {
JEditorPane pane = null;
JFrame f = new JFrame();
f.setSize(400, 400);
f.setLocation(150, 100);
f.getContentPane().setLayo
try {
pane = new JEditorPane("https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20152577");
} catch(Exception e) {}
f.getContentPane().add(new
f.setVisible(true);
}
}
You must wait a little until the page is loaded.
To Ovi :
Did you succeed to show the page in this way ?
Some security exceptions are shown at console...
catch(Exception e) {
e.printStackTrace();
}
JEditorPane supports HTML3.2 and and lower.
I think something else should be added...
Best Regards
Valeri
Did you succeed to show the page in this way ?
Some security exceptions are shown at console...
catch(Exception e) {
e.printStackTrace();
}
JEditorPane supports HTML3.2 and and lower.
I think something else should be added...
Best Regards
Valeri
That code won't work from an unsigned applet.
on my computer is wotking fine (it loads the page) whitout any exceptions. I use JDK 1.3.1. Try to replace the url with www.altavista.com
Who has said that is needed in an applet ? :)
No-one, but i'll bet that's what Valeri's problem is.
Maybe
I tried the proposed example with JDK 1.2:
AppAccelerator(tm) 1.2.010 for Java (JDK 1.2), x86 version.
Copyright (c) 1997-1999 Inprise Corporation. All Rights Reserved.
java.net.SocketException: Connection reset by peer: no further information
at java.net.PlainSocketImpl.s ocketConne ct(Native Method)
at java.net.PlainSocketImpl.d oConnect(C ompiled Code)
at java.net.PlainSocketImpl.c onnectToAd dress(Comp iled Code)
at java.net.PlainSocketImpl.c onnect(Com piled Code)
at java.net.Socket.<init>(Com piled Code)
at java.net.Socket.<init>(Com piled Code)
at sun.net.NetworkClient.doCo nnect(Comp iled Code)
at sun.net.www.http.HttpClient.openServer(Compiled Code)
at sun.net.www.http.HttpClient.openServer(Compiled Code)
at sun.net.www.http.HttpClient.<init>(Compiled Code)
at sun.net.www.http.HttpClient.<init>(Compiled Code)
at sun.net.www.http.HttpClient.New(Compiled Code)
at sun.net.www.protocol.http.HttpURLConnection.connect(Compiled Code)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Compiled C
ode)
at javax.swing.JEditorPane.ge tStream(JE ditorPane. java:485)
at javax.swing.JEditorPane.se tPage(JEdi torPane.ja va:309)
at javax.swing.JEditorPane.se tPage(JEdi torPane.ja va:555)
at javax.swing.JEditorPane.<i nit>(JEdit orPane.jav a:185)
at TestHTML.main(TestHTML.jav a:41)
AppAccelerator(tm) 1.2.010 for Java (JDK 1.2), x86 version.
Copyright (c) 1997-1999 Inprise Corporation. All Rights Reserved.
java.net.SocketException: Connection reset by peer: no further information
at java.net.PlainSocketImpl.s
at java.net.PlainSocketImpl.d
at java.net.PlainSocketImpl.c
at java.net.PlainSocketImpl.c
at java.net.Socket.<init>(Com
at java.net.Socket.<init>(Com
at sun.net.NetworkClient.doCo
at sun.net.www.http.HttpClient.openServer(Compiled Code)
at sun.net.www.http.HttpClient.openServer(Compiled Code)
at sun.net.www.http.HttpClient.<init>(Compiled Code)
at sun.net.www.http.HttpClient.<init>(Compiled Code)
at sun.net.www.http.HttpClient.New(Compiled Code)
at sun.net.www.protocol.http.HttpURLConnection.connect(Compiled Code)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Compiled C
ode)
at javax.swing.JEditorPane.ge
at javax.swing.JEditorPane.se
at javax.swing.JEditorPane.se
at javax.swing.JEditorPane.<i
at TestHTML.main(TestHTML.jav
OK, with the first URL or the second ?
ASKER
U must be behind a firewall.
Run using
java -Dhttp.proxyHost=host -Dhttp.proxyPort=port TestHTML
Run using
java -Dhttp.proxyHost=host -Dhttp.proxyPort=port TestHTML
For k_suchdeva :
Fits your needs ?
Fits your needs ?
With the first one :
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20152577
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20152577
So,
How can I show html file that is placed at my local disk?
Best Regards,
Valeri
How can I show html file that is placed at my local disk?
Best Regards,
Valeri
like you do in your browser. Something like 'file:// ... path to your file'
yo man :!
k_suchdeva,
You have a number of open questions; please review the list below and see if you can bring them to some resolution.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11664998
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11721238
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11733458
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20010074
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20073732
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20152577
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20157736
Thank you,
Netminder
Community Support Moderator
Experts Exchange
You have a number of open questions; please review the list below and see if you can bring them to some resolution.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11664998
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11721238
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11733458
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20010074
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20073732
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20152577
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20157736
Thank you,
Netminder
Community Support Moderator
Experts Exchange
Hopefully you've already been helped with this question, but thought you'd appreciate knowing this.
WindowsUpdate has new updates for .NET users; Details follow - Microsoft .NET Framework
The .NET Framework is a new feature of Windows. Applications built using the .NET Framework are more reliable and secure. You need to install the .NET Framework only if you have software that requires it.
For more information about the .NET Framework, see http://www.microsoft.com/net. (This site is in English.)
System Requirements
The .NET Framework can be installed on the following operating systems:
Windows 98
Windows 98 Second Edition (SE)
Windows Millennium Edition (Windows Me)
Windows NT 4.0® (Workstation or Server) with Service Pack 6.0a
Windows 2000 with the latest service pack installed (Professional, Server, Datacenter Server, or Advanced Server)
Windows XP (Home Edition and Professional)
You must be running Internet Explorer version 5.01 or later for all installations of the .NET Framework.
To install the .NET Framework, your computer must meet or exceed the following software and hardware requirements:
Software requirements for server operating systems:
MDAC 2.6
Hardware requirements:
For computers running only a .NET Framework application, Pentium 90 mHz CPU with 32 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
For server operating systems, Pentium 133 mHz CPU with 128 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
Recomended software:
MDAC 2.7 is recommended.
Recommended hardware: For computers running only a .NET Framework application, Pentium 90 MHz CPU with 96 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
For server operating systems, Pentium 133 MHz CPU with 256 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
How to use -> Restart your computer to complete the installation. No other action is required to run .NET Framework applications. If you are developing applications using the .NET Framework, you can use the command-line compilers or you can use a development environment, such as Visual Studio .NET, that supports using the .NET Framework.
How to uninstall
To uninstall the .NET Framework: Click Start, point to Settings, and then click Control Panel (In Windows XP, click Start and then click Control Panel.).
Click Add/Remove Programs.
Click Microsoft .NET Framework (English) v1.0.3705 and then click Change/Remove.
More here http://www.microsoft.com/net/
The .NET topic is being considered for addition to our All Topics link soon, so this may interest you as well:
https://www.experts-exchange.com/newtopics/Q.20276589.html
EXPERTS POINTS are waiting to be claimed here: https://www.experts-exchange.com/commspt/Q.20277028.html
":0)
Asta
WindowsUpdate has new updates for .NET users; Details follow - Microsoft .NET Framework
The .NET Framework is a new feature of Windows. Applications built using the .NET Framework are more reliable and secure. You need to install the .NET Framework only if you have software that requires it.
For more information about the .NET Framework, see http://www.microsoft.com/net. (This site is in English.)
System Requirements
The .NET Framework can be installed on the following operating systems:
Windows 98
Windows 98 Second Edition (SE)
Windows Millennium Edition (Windows Me)
Windows NT 4.0® (Workstation or Server) with Service Pack 6.0a
Windows 2000 with the latest service pack installed (Professional, Server, Datacenter Server, or Advanced Server)
Windows XP (Home Edition and Professional)
You must be running Internet Explorer version 5.01 or later for all installations of the .NET Framework.
To install the .NET Framework, your computer must meet or exceed the following software and hardware requirements:
Software requirements for server operating systems:
MDAC 2.6
Hardware requirements:
For computers running only a .NET Framework application, Pentium 90 mHz CPU with 32 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
For server operating systems, Pentium 133 mHz CPU with 128 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
Recomended software:
MDAC 2.7 is recommended.
Recommended hardware: For computers running only a .NET Framework application, Pentium 90 MHz CPU with 96 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
For server operating systems, Pentium 133 MHz CPU with 256 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
How to use -> Restart your computer to complete the installation. No other action is required to run .NET Framework applications. If you are developing applications using the .NET Framework, you can use the command-line compilers or you can use a development environment, such as Visual Studio .NET, that supports using the .NET Framework.
How to uninstall
To uninstall the .NET Framework: Click Start, point to Settings, and then click Control Panel (In Windows XP, click Start and then click Control Panel.).
Click Add/Remove Programs.
Click Microsoft .NET Framework (English) v1.0.3705 and then click Change/Remove.
More here http://www.microsoft.com/net/
The .NET topic is being considered for addition to our All Topics link soon, so this may interest you as well:
https://www.experts-exchange.com/newtopics/Q.20276589.html
EXPERTS POINTS are waiting to be claimed here: https://www.experts-exchange.com/commspt/Q.20277028.html
":0)
Asta
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points NOT refunded
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
vemul
Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points NOT refunded
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
vemul
Cleanup Volunteer
the questions been answered imo
per recommendation.
SpideyMod
Community Support Moderator @Experts Exchange
objects,
Moderators cannot be expected to be knowledgeable in every area, it would be most helpful if you would provide an expert name for whom to assign the 100 points in your comments. I have removed the points from this question but can issue a points for expertname question if if you post whom you think should get the points. Thanks.
SpideyMod
Community Support Moderator @Experts Exchange
objects,
Moderators cannot be expected to be knowledgeable in every area, it would be most helpful if you would provide an expert name for whom to assign the 100 points in your comments. I have removed the points from this question but can issue a points for expertname question if if you post whom you think should get the points. Thanks.
I believe I first answered the original question :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
objects,
Your points are here. If you'll post there, I'll close tomorrow (Spidey needs his rest tonight, more crime to fight tomorrow).
https://www.experts-exchange.com/questions/20452261/points-for-objects-re-20152577.html
Your points are here. If you'll post there, I'll close tomorrow (Spidey needs his rest tonight, more crime to fight tomorrow).
https://www.experts-exchange.com/questions/20452261/points-for-objects-re-20152577.html
Closed.
Netminder
EE Admin
Netminder
EE Admin
For HTML support use JEditorPane.