How I can I Html in Java textarea?

Can anybody give a example to put Html text in textarea. I will be very glad if anybody can help me in this regard.

Use a javax.swing.JTextPane. It has a setPage, but several ways may lead to HTML.
Set it to read-only. Ensure it uses text/html not text/plain.
try {
        String url = "http://java.sun.com";
        JEditorPane editorPane = new JEditorPane(url);
        editorPane.setEditable(false);
        JFrame frame = new JFrame();
        frame.getContentPane().add(editorPane, BorderLayout.CENTER);
        frame.setSize(width, height);
        frame.setVisible(true);
    } catch (IOException e) {
    }Add a HyperlinkListener.
import javax.swing.*;
import javax.swing.event.*;
public class LinkFollower implements HyperlinkListener {
  private JEditorPane pane;
  public LinkFollower(JEditorPane pane) {
    this.pane = pane;
  public void hyperlinkUpdate(HyperlinkEvent evt) {
    if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      try {
        pane.setPage(evt.getURL());       
      catch (Exception e) {       

Similar Messages

  • How to display formated html in a TextArea?

    Hi,
    I'm trying to display some html in a TextArea. But the formatting does not look good.
    here is my mxml file
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
         width="100%" height="100%">
              <mx:TextArea id="legend"
                   width="100%" height="100%" editable="false" selectable="false" toolTip="map legend" wordWrap="true">
                   <mx:htmlText>
                        <![CDATA[
                             <p><img src="images/projects.png" /> projects</p>
                             <p><img src="images/publications.png" /> pubpcations</p>
                             <p><img src="images/persons.png" /> persons</p>
                             <p><img src="images/news.png" /> news</p>
                             <p><img src="images/events.png" /> events</p>
                             <p><img src="images/documents.png" /> documents</p>
                        ]]>
                   </mx:htmlText>
              </mx:TextArea>
    </mx:Panel>
    and here is the result...
    Any idea what I am doing wrong?

    I had problems like what you are describing. A picture is worth a thousand words, so take a lookee here: http://www.timos.com/timos/green/ct/CounterThink.cfm. When the app displays, press the link button "About CounterThink", then scroll down to the text block with Mike Adams' photo.
    My problems were fixed when I eliminated all the spaces in the HTML code. My source code for that block now looks like this:
    <p><img src="../../assets/images/green/mike.png" alt="Mike Adams" width="150" height="149" hspace="5" vspace="3" align="left" />The creator of the cartoons, <b>Mike Adams</b> is a consumer health advocate with a mission to teach personal and planetary health to the public He is a prolific writer and has published thousands of articles, interviews, reports and consumer guides, impacting the lives of millions of readers around the world who are experiencing phenomenal health benefits from reading his articles. Adams is an honest, independent journalist and accepts no money or commissions on the third-party products he writes about or the companies he promotes.</p><p></p><p>In 2007, Adams launched EcoLEDs, a manufacturer of mercury-free, energy-efficient LED lighting products that save electricity and help prevent global warming. He's also a successful software entrepreneur, having founded a well known email marketing software company whose technology currently powers the NaturalNews email newsletters.</p><p></p><p>Adams is currently the executive director of the Consumer Wellness Center, a 501(c)3 non-profit, and regularly pursues cycling, nature photography, Capoeira and Pilates. Known as the 'Health Ranger', Adams' personal health statistics and mission statements are located at <a href=http://www.healthranger.org target="_blank"><u>www.HealthRanger.org</u></a>.</p>
    Notice there are no indents, no line breaks, not a single space except for those within the text. The code is a little harder to read this way, but that is what worked. Try it, I hope this works for you. Have fun,
    Carlos

  • J2ee Webservices(How i can send Image from java to C sharp)

    Dear Everyone
    Hi
    I am currently working on J2EE base web services project.
    I want to transfer some binary data as Images or files to client as (client written in c sharp).
    How i can do this exactly because i have no idea
    I am usnig sun App Server or JWSDP for this purpose
    Is there any one who has some experience with such knowledge.
    Kindly give me ur suggestions regarding this.
    Kind Regard
    kashif

    Thanks for the quick reply...i tried that and it works ...but not sure how to release that memory got from " New " and sure....there results memoryleak.this method will be called about 50 lakh plus times...so application suffers due to this memory leak....is any way i can avoid using New with in my Dll.....?

  • How i can use ExportPDF in java code to get html files as PDF?

    I need to use ExportPDF in java code to export my html to PDF and save that in my local system.

    Yes, it's not a service for automating. Automating Acrobat is a possibility (though awkward), or there are server products.

  • How i can start working with Java?

    Right now i am having only 8 months of exp in ABAP. can any one help me out to start working with Java specially for Netweaver Purpose

    It is great if you can get yourself familiar with java syntax, as is the case with any new langauage. However, the worst thing you can do is just code java in a top down approach. If you are not familiarizing yourself with OO concepts and best practices, then you are going to miss two important benefits that you will get from using OO programming - Reusability and flexibility in the frameworks that you develop (leveraging design patterns).
    These benefits will also be directly obtainable when you use ABAP objects.
    I am working in the opposite direction at the moment. I have some java experience, and I am starting to learn ABAP. I have used ABAP objects in my first project, and it was actually much better than I thought it would to be.
    Java and OO programming will be an ongoing learning experience. You will not be an expert for quite some time. I do not consider myself to be an expert by any means, and I've be studying OO and java for a few years.
    There is a fantastic book that explains OO concepts clearly, in much easier terms than the Gof "Design Patterns" book:
    Java Design: Objects, UML, and Process by Kirk Knoernschild
    You can read a few chapters at www.kirkk.com. (Use the JOUP link).
    Hope this helps you.
    - Brendan

  • Does anyone know how i can embed a browser in my JFrame?

    In microsoft technologies they have OLE, where I can embed Internet Explorer into any application written in VB or C++ (or C Sharp).
    Does anyone know how I can do this with Java? Is there a way to make a java applet that has a browser in it?
    And then if there is, can I also put an invisible layer on top of that, and paste JLabels and stuff into that, over the browser window?

    Have a look at JEditorPane.
    From the API Guide:
    A text component to edit various kinds of content. This component uses implementations of the EditorKit to accomplish its behavior. It effectively morphs into the proper kind of text editor for the kind of content it is given. The content type that editor is bound to at any given time is determined by the EditorKit currently installed. If the content is set to a new URL, its type is used to determine the EditorKit that should be used to load the content.
    By default, the following types of content are known:
    text/plain
    Plain text, which is the default the type given isn't recognized. The kit used in this case is an extension of DefaultEditorKit that produces a wrapped plain text view.
    text/html
    HTML text. The kit used in this case is the class javax.swing.text.html.HTMLEditorKit which provides html 3.2 support.
    text/rtf
    RTF text. The kit used in this case is the class javax.swing.text.rtf.RTFEditorKit which provides a limited support of the Rich Text Format.

  • How do I suppress the "Outdated Java Runtime Environment" message?

    Hi,
    Does anyone know how I can suppress this "Outdated Java Runtime Environment" message?
    I'm currently running 1.4.2.12 alongside the latest version of 1.6.x
    Each time I start an applet coded to run with 1.4.2.12 a security warning appears titled "Outdated Java Runtime Environment" saying that:
    "A Java applet in this webpage requires the Java Runtime Envronment (JRE 1.4.2 to run. You have JRE 1.4.2 installed, but not the latest release. Using an old release may present security risks. Do you want to run the applet anyway?"
    YES / NO
    I don't want to upgrade to 1.4.2.19 and this problem will occur again is 1.4.2.20 arrvies...
    So how can I suppress this warning message?
    I can't see anything in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy that can be turned off.
    I've tried the obvious:
    EnableAutoUpdateCheck = 0
    EnaleJavaUpdate = 0
    Update schedule = 0
    In fact, everything under "Policy" has been set to "0"
    Any ideas? Is there an unknown registry switch or something that can be added to the startup script that turns off this version/security check?
    Any advice would be useful.

    While looking for something else, I accidentally found the following message:
    [t-5253971]
    The 3rd post in that thread (i.e. the 2nd reply) claims to have an answer. I haven't tried it (though if you do try it I would be interested to know if it works).

  • How to connect via telnet with Java?

    I want to develop an application in a server with solaris 8. I want to access from this server to another server in a LAN via telnet and write down the information i am getting in a file. How i can do this in java? it's a good alternative? or i should try C++. Thanks in advance.!

    You can easily use java....just get a hold of the RFC for Telnet or if you look around, you can find code on the net already working.

  • How to execute PL/SQL from Java?

    I want to execute (compile) a PL/SQL file to a database and I don't know how it can be done with Java.
    Please note that I am NOT trying to call a stored procedure. I know that can be done with CallableStatement.
    Background:
    My actual requirement is to execute PL/SQL files with error notifications. I tried Ant SQL task; but it fails to give compilation error information. I also tried another open source task called Incanto - that also not that helpful as if I execute in bulk, very hard to figureout which one throws error. Hence I decided to write my own Ant task.

    Hi,
    do u want to execute PL/SQL files? or just you want to execute the block of code?
    in the case of PL/SQL file:
    you need to read total file as StringBuffer/String and then execute.
    Block of code:
    you can directly pass the code to the java file as input and then execute.
    Ex:
                   StringBuffer queryString = new StringBuffer();
                    queryString = queryString.append("BEGIN execute immediate ' ");
              queryString = queryString.append(query);
              //queryString = queryString.append("BEGIN dbms_job.run(142);END;");
              queryString = queryString.append(" '; END; ");
              final_Query = queryString.toString();
              try {
                   System.out.println("final :   "+final_Query);
                   cstmt = con.prepareCall(final_Query);
                   System.out.println("Job is Running...");
                   new ThreadCountdownExtThread().start();
                   System.out.println("bfore execute()...............");
                   cstmt.execute();Note: if you are running pl/sql file read file and save it in a Stirng , and then do the same as above stated

  • How i can set the selected item of a dropDown component from java code

    Hi
    Thank you for reading my post
    How i can set the slected item of a DropDown component from backing beans java code ?
    it is binded with a database , so one field determine its display and one other field determine its value , I want to set the selected item of this combobox
    In back code i have both value and display values to use them .
    can some one give me some help ?
    Thanks ,

    See code sample 3 at http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/helloweb.html
    See also, the selection components row in the table under http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/helloweb.html
    It says
    One way to preselect items is to call setSelectedValue(Object[]) or setSelectedValue(Object) from the prerender() method. You pass in the return values of the items that you want preselected. Be sure to verify that getSelected() returns null before setting the default options, or you will overwrite the user's selections on a post-back.

  • I can not get Firefox to play music backgrounds on pages in browsers it works in IE and other browsers but not firefox, what HTML or Jave script do I need too use to make them work?

    I'm having a problem with firefox playing background music on some sites, it works with IE and other browsers but not with fire fox, what html or java script do I need to add to the pages so that they play the music?
    I develop my pages in Front Page and I know that the music only works in IE, so if someone can tell me how to correct this problem as it is important as I use fire fox as my main browser.
    I thank you in advance

    If a website uses BGSOUND then it will only work in IE.
    BGSOUND is not compatible with other browsers like Firefox.
    * http://kb.mozillazine.org/Background_music_does_not_play

  • How can I set the java Date not greater than the day inputed?

    When I would input the date, I don't want it to be after this day because it would violate some business logic in my program. I am allowed to input date latter than this day like yesterday, last week etc. but not after this day.....Can anyone give me a concrete example or logic on how to do this?THANKS!

    tr3k wrote:
    Can you explain it by code?I could, but I won't. I pointed you in the right direction. Now it's up to you to make the effort. Give it your best shot and post a more detailed question if you have problems.
    http://www.javaworld.com/jw-12-2000/jw-1229-dates.html
    http://www.javaalmanac.com/egs/java.text/FormatDate.html
    http://www.javaalmanac.com/egs/java.text/ParseDate.html
    http://java.sun.com/javase/6/docs/api/java/util/Date.html
    http://java.sun.com/javase/6/docs/api/java/util/Calendar.html
    http://java.sun.com/javase/6/docs/api/java/util/GregorianCalendar.html
    http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html

  • Parsing HTML from Java, How

    Problem:
    I need to Connect to a URL using Java.
    Then i need to detect/ parse the html of the url for Image contents
    *So that i can replace some thing rather than the image such as with the text [IMAGE].*
    I already able to connect and read the htmls of url. But i need ur help regarding parsing for image links.
    Just i need to parse the html page to sense image links/contents on that page.
    How it can be done?

    hi shazzad,
    Could you please try with this,
    * XsdReader.java
    * Created on September 12, 2008, 11:36 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package EDITool;
    import java.io.File;
    import java.io.IOException;
    import java.util.Hashtable;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    * @author Rajesh
    public class XsdReader {
        /** Creates a new instance of XsdReader */
        private DocumentBuilder docBuilder;
        private Document doc;
        private DocumentBuilderFactory docBuilderFactory;
        private File xsdFile;
        private File xmlFile;
        private Hashtable dataList;
        private String modXML = "";
        public XsdReader() {
            docBuilder = null;
            doc = null;
            docBuilderFactory = DocumentBuilderFactory.newInstance();
            try{
                    docBuilder = docBuilderFactory.newDocumentBuilder();
            catch(ParserConfigurationException e)
                    System.out.println("Wrong parser configuration: " + e.getMessage());
            this.xsdFile = null;
            this.xmlFile = null;
            dataList = new Hashtable();
        public class Attr{
        private String minOccurs;
        private String maxOccurs;
        public Attr(String minOccurs, String maxOccurs)
                this.minOccurs = minOccurs;
                this.maxOccurs = maxOccurs;
        public void xsdParser(String xsdInputFileName,int level)
            try{
                this.xsdFile = new File(xsdInputFileName);
            catch(Exception e)
                System.out.println("File Not Exception: "+e);
            try{
              doc = docBuilder.parse(this.xsdFile);
                    NodeList nodeList = doc.getChildNodes();
                    xsdRecursive(nodeList,level);
         catch(SAXException e)
              System.out.println("Wrong XML file structure: " + e.getMessage());
         catch(IOException e)
              System.out.println("Wrong XML file structure: " + e.getMessage());
         catch(Exception e)
              System.out.println("Error: "+e);
        public void xsdRecursive(NodeList nodeList, int level)
            try{
              for(int i=0;i<nodeList.getLength();i++)
                   Node node = nodeList.item(i);
                   if(node.getNodeType() == node.ELEMENT_NODE  && level == 1)
                        if(node.hasAttributes())
                             Element e = (Element)node;
                             String minOccursValue = e.getAttribute("minOccurs");
                             if(!minOccursValue.equals(""))
                                  String name = e.getAttribute("name");
                                  if(name.equals(""))
                                  name = e.getAttribute("ref");
                                  if(name.equals(""))
                                  continue;
                                  String minOccurs = e.getAttribute("minOccurs");
                                  String maxOccurs = e.getAttribute("maxOccurs");
                                  System.out.println(name);
                                  this.dataList.put(name,new Attr(minOccurs,maxOccurs));
                            else if(node.getNodeType() == node.ELEMENT_NODE  && level == 2)
                                String currentTagName = node.getNodeName();
                                Attr attr = (Attr)this.dataList.get(currentTagName);
                                NamedNodeMap nodeAttr = node.getAttributes();
                                org.dom4j.Node dom4jNode = (org.dom4j.Node) node;
                                org.dom4j.Element e = (org.dom4j.Element) dom4jNode;
                                e.addAttribute("min", attr.minOccurs);
                                e.addAttribute("max", attr.maxOccurs);
                   if(node.hasChildNodes())
                   xsdRecursive(node.getChildNodes(),level);
              catch(Exception e)
                   System.out.println("Error: "+e);
        public void xsdRecursive(Node node, int level)
            NodeList nodeList = node.getChildNodes();
            try{
                for(int i=0;i<nodeList.getLength();i++)
                if(node.getNodeType() == Node.ELEMENT_NODE )
                   // if(level == 1)
                    if(node.hasAttributes())
                        Element e = (Element)node;
                        String minOccursValue = e.getAttribute("minOccurs");
                        if(!minOccursValue.equals(""))
                                String name = e.getAttribute("name");
                                if(name.equals(""))
                                name = e.getAttribute("ref");
                                String minOccurs = e.getAttribute("minOccurs");
                                String maxOccurs = e.getAttribute("maxOccurs");
                                System.out.println(name);
                                this.dataList.put(name,new Attr(minOccurs,maxOccurs));
                    else if(level == 2)
                    System.out.println("rajesh");
                    String currentTagName = node.getNodeName();
                    Attr attr = (Attr)this.dataList.get(currentTagName);
                    NamedNodeMap nodeAttr = node.getAttributes();
                    org.w3c.dom.Attr minAttr = ((Document)node).createAttribute("min");
                    minAttr.setValue(attr.minOccurs);
                    org.w3c.dom.Attr maxAttr = ((Document)node).createAttribute("max");
                    minAttr.setValue(attr.maxOccurs);
                    Element e =(Element)node;
                    System.out.println(e.getNodeName()+"\t"+e.getAttribute("min"));
            catch(Exception e)
                System.out.println("Exception in xsdRecursive: "+e);
        public void display()
            Attr attr = (Attr) this.dataList.get("ISA01");
            System.out.println(attr.maxOccurs+"\t"+attr.minOccurs);
        public static void main(String s[])
            XsdReader xsdReader = new XsdReader();
            //String xsdInputFileName = "C:/Documents and Settings/vs73471/Documents/SAP/workspace/Sample/src/packages/com/sap/java/Copy of 850.xml";
            String xsdInputFileName = "C:/Documents and Settings/vs73471/Desktop/www.html";
            xsdReader.xsdParser(xsdInputFileName, 1);
            System.out.println(xsdReader.dataList.size());
            String xmlInputFileName = "C:/Documents and Settings/vs73471/Desktop/Reference XML Generate/850_Dummy.xml";
            xsdReader.xsdParser(xmlInputFileName, 2);
          //  xsdReader.display();
    }

  • How i can open a new command prompt from one java from

    hi
    can any one help me that how i can open a command prompt by using the java program file .
    regards,
    ukbasak

    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String)
    and several overloads.
    Also
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html

  • How can i open my Java aplication...

    Hi everybody!
    I was wondering how can i open my Java Picture Viewer by presing an picture.
    When i am running the program with an argument like this
    --> java JPic <path to picture> its ok.
    But i want to press the image and automaticly open my Java Program.
    How can i do that?
    I have to use a native method?
    The source of my program is here:
    http://aetos.it.teithe.gr/~athoik/myprograms/jpic/jpic.html
    Every help IS ACCEPTABLE AND NECESSARY.

    I find it how it works. Al you need to do is make a script. So by presing a picture with your
    mouse or on shell the program run with the specific picture as input :)
    Cool!!
    ##### For Windos Script .bat ######
    @cd C:\
    @cd "C:\path to program\"
    @java -jar JPic.jar %1
    @pause
    ###### For Linux Script ########
    @cd /where the program is
    @java -jar JPic.jar $1

Maybe you are looking for

  • Problem with preview PDF files on Windows 7 32bit

    Hello, in my office I have a problem with preview PDF files on my computers. The files are allright, but if I select a file and click on preview mode after ~ 10sec operation system write something "Preview this file is corrupt for PDF Preview Handler

  • Item Text in Purchase Order Transfer to GR (Material Document)

    Hi, Is there a way tro transfer the Item text in the PO to the GR or Material Document. Thanks, jograd

  • Why did the "custom" size option disappear from list when creating a PDF in Photoshop?

    For my job, I must have the custom option available to me in Photoshop. I'm currently using CS4 and have been for years without a problem. Yesterday "custom" option from the choose size list disappeared, along with several other options (that I don't

  • Background Image/Watermark

    I've searched the API's and the sample code. I can't seem to find an easy way to set a background image. Seeing as how I am a newbie at this perhaps I just don't know how to work with the classes as well as I thought. Any suggestions, code samples or

  • My MBP 2011 can't detect microphone, why?

    My internal microphone works perfectly fine but when I insert an external microphone, my MBP fails to detect it.  When I go to System Preferences>Sound>Input, nothing changes in the "Line In" area when I plug in my microphone.  When I try to speak in