Hyperlinkable TextArea

Can someone give me a clue on how to make the URL displayed in the TextArea hyperlinkable. The Program displays http://www.yahoo.com but I want to be able to click on it and have it open into a new browser. It currently runs fine without the hyperlink but has compile errors. Thanks :^)
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import javax.swing.JEditorPane.*;
import javax.swing.text.html.*;
public class Hyperlinkdemo
     public static void main(String[] args)
          JEditorPane myEditorPane;
          myEditorPane.addHyperlinkListener(new MyHyperlinkListener());
          final String website = "http://www.yahoo.com";
          JLabel msgLabel = new JLabel("Hyperlinkable Test Program");
          JButton runButton = new JButton("Run");
          final TextArea output = new TextArea(10,30);
          JScrollPane scroller = new JScrollPane(output);
          JFrame frame = new JFrame("Hyperlinkdemo");
          JPanel buttonbox = new JPanel();
          JPanel jp = new JPanel();
          JPanel northPanel = new JPanel();
          frame.getContentPane().setLayout(new BorderLayout());
          jp.setLayout(new FlowLayout());
          jp.add(scroller);
          northPanel.add(msgLabel);
          northPanel.add(runButton);
          website.add(myEditorPane);
          frame.getContentPane().add(northPanel, "North");
          frame.getContentPane().add(jp, "South");
          runButton.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e){
                    output.append(website + "\n");
          frame.pack();
          frame.show();
     class MyHyperlinkListener implements HyperlinkListener {
     public void hyperlinkUpdate(HyperlinkEvent evt) {
     HyperlinkEvent.EventType type = evt.getEventType();
     if (type.equals(HyperlinkEvent.EventType.ACTIVATED)) {
     myEditorPane.setPage(evt.getURL());
}

Well i'm sure there are a lot of others that can help you better than myself, but i think the key to your problem is in your JEditorPane call setEditable(false). The Java API itself has a good example under JEditorPane.
Here's what i came up with after modifying your code
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.text.html.*;
import java.io.*;
public class Hyperlinkdemo
JEditorPane myEditorPane;     
final String website = "http://www.yahoo.com";
public void init()
myEditorPane = new JEditorPane("text/html","");
myEditorPane.addHyperlinkListener(new MyHyperlinkListener());
myEditorPane.setEditable(false);
JLabel msgLabel = new JLabel("Hyperlinkable Test Program");
JButton runButton = new JButton("Run");
JScrollPane scroller = new JScrollPane();
scroller.setViewportView(myEditorPane);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JFrame frame = new JFrame("Hyperlinkdemo");
JPanel buttonbox = new JPanel();
JPanel northPanel = new JPanel();
northPanel.add(msgLabel);
northPanel.add(runButton);
frame.getContentPane().add(northPanel, "North");
frame.getContentPane().add(scroller);
runButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
myEditorPane.setText("<a href=\"http://www.yahoo.com\">www.yahoo.com</a>");
System.out.println(myEditorPane.getContentType());
frame.addWindowListener(new MyWindowAdapter());
frame.pack();
frame.setSize(300,300);
frame.show();
class MyWindowAdapter extends WindowAdapter
     public void windowClosing(WindowEvent e)
          System.exit(0);     
public static void main(String args[])
     Hyperlinkdemo demo = new Hyperlinkdemo();
     demo.init();     
class MyHyperlinkListener implements HyperlinkListener
public void hyperlinkUpdate(HyperlinkEvent e)
     HyperlinkEvent.EventType type = e.getEventType();
     if (type.equals(HyperlinkEvent.EventType.ACTIVATED))
          JEditorPane pane = (JEditorPane) e.getSource();
          JEditorPane another = new JEditorPane();
          JFrame newframe = new JFrame("New window");
          if (e instanceof HTMLFrameHyperlinkEvent)
          HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)e;
          HTMLDocument doc = (HTMLDocument)pane.getDocument();
          doc.processHTMLFrameHyperlinkEvent(evt);
          else
          try
                    another.setPage(e.getURL());
                    newframe.getContentPane().add(another);
                    newframe.pack();
                    newframe.setSize(100,100);
                    newframe.show();
          catch (Throwable t)
               t.printStackTrace();
It provides a hyperlink after the RUN button is clicked, and pops the clicked result in another frame. Hope this helps

Similar Messages

  • TextArea hyperlink styling

    Although Flex Builder 3 gives a wide variety of controls over
    the style of a TextArea, I have not found a property that allows
    styling of hyperlinks. I would like to be able to have htmlText
    shown in a TextArea to have styling for hyperlinks, including
    different styles for the pseudo-classes of hover, etc.
    I have seen a couple of complex workarounds for this from FB
    2 days, but would love to find a simple or elegant way to
    accomplish this.
    Thanks in advance,
    James

    I have found a way to do this reasonably easily. Here is what
    I did:
    1. Include in <mx:Application>:
    creationComplete="defineStyles();"
    2. ....which refers to this function and the variable it
    needs:
    <mx:Script>
    <![CDATA[
    public var ss:StyleSheet = new StyleSheet();
    public function defineStyles():void
    this.styledTxt.styleSheet = this.ss;
    var h:Object = new Object();
    h.color = "#970909";
    h.textDecoration = "underline";
    ss.setStyle("a:hover", h);
    var a:Object = new Object();
    a.color = "#0066ff";
    a.textDecoration = "none";
    ss.setStyle("a:link", a);
    var v:Object = new Object();
    v.color = "#0066ff";
    v.textDecoration = "none";
    ss.setStyle("a:visited", v);
    var t:Object = new Object();
    t.color = "#0066ff";
    t.textDecoration = "none";
    ss.setStyle("a:active", t);
    ]]>
    </mx:Script>
    3. And id your TextArea as id="styledTxt"
    -=-=-=-=-=-
    You may of course adjust variables above as needed.
    I am using this for an application that imports blog postings
    through HTTPService, and for my content call I use
    htmlText="{gettheItem.lastResult.item.thetext}" referring to that
    HTTPService call. I mention this so that you can know that this
    styling is working on bulk imported data that has anchor links in
    it and is properly showing them with the styling I have specified.
    Note that this posting from the Flashlit blog was helpful to
    me:
    http://rantworld.blogs.com/flashlit/2006/08/styling_flex_te.html
    I hope this is helpful,
    James

  • TextArea with formatted Text, Hyperlinks, and clickable Text with SWING?

    Hi again,
    Ok if I decide to use Swing, is there any TextArea which supports Formatted Text Hyperlinks AND clickable Text wich calls a callback routine??? I think formatted Text and Hyperlinks are possible with JTextArea and the RTF editorKit, but clickable text, in order to controll the program in some way???
    Could anyone help me?
    Greets

    Try the JEditorPane class.See the intro exapmle at the top of
    [url=http://java.sun.com/j2se/1.4.2/docs/api/javax/swin
    /JEditorPane.html] this page.That seems to be the solution! Can I use the JTextPane, too? Does a DefaultStyledEditorKit support Hyperlinks and Hyperlinklisteners, too?
    In order to realize callback functions I have to insert a HTML-Anchor with the Attribute as the Parameter for my method. Then my HyperlinkListener catches the HyperlinkEvent and the hyperlinkUpdate method reminds the parameter!
    Is that right?
    Thank you very much!
    Greets

  • Can i make a Hyperlink in a TextArea?

    I want to make a link to a picture..or another form or file in a TextArea
    is it possible?
    if so how?

    http://java.sun.com/docs/books/tutorial/uiswing/components/text.html

  • How to make hyperlinks in JTextField/JtextArea  ??

    My JTextField/JtextArea has got this Text.
    String text = "Get information from http://www.hotmail.com, if you have problems go to http://www.google.com " ;
    How to make hyperlinks for http://www.hotmail.com and http://www.google.com texts only???
    And how to call those sites???

    Add a mouse listener, when the user double clicks - see if they've clicked on text that is a valid link.
    The limitation of using textfield or textarea is that you get no styling. I dont know why you're refusing those suggestions, but you're just creating more work for yourself.

  • How to use embedded image in TextArea in Air (differs from Flex) ?

    So I was trying the example from the LiveDocs:
    Making hyperlinks out of embedded images
    http://livedocs.adobe.com/flex/3/html/help.html?content=textcontrols_04.html
    This doesn't seem to work in an Air application (the image doesn't show).
    Even simply adding an image with a relative path doesn't work in Air (the image doesn't show either):
        <mx:Image source="../assets/butterfly.gif" />
    I'm sure I must be missing something really straightforward here, can anyone help ?
    Also, more generally, where I can see the source code of TextArea and RichTextEditor, understanding their inner working would be a great help.
    Thanks

    Embedding images in htmlText in a TextFiled isn't supported in AIR.
    See: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.ht ml#htmlText
    The source for the Flex components is included in the Flex SDK.

  • TLF applying hyperlinks issue

    Hi,
    I have a textArea in which I have assigned a textflow. On the text if I want to apply a hyperlink then I give a URL and target. Now if I haven't applied any other formatting to the text it creates a hypelink and makes the text blue and underlined, which is the normal case.
    Now suppose I change the fontSize of the text and then apply a hyperlink, then the link gets applied, but the text neither gets any color , nor does it become underlined.
    But if I do a Ctrl + Click on the same text, my link gets opened. But the hyperlink styling doesn't get applied.
    This is what I am doing for applying link to some text:
    public function changeLink( urlLink : String, target : String,  extendToOverlappingLinks : Boolean):void
                if ( myTextArea.textFlow && myTextArea.textFlow.interactionManager is IEditManager)
                     IEditManager(myTextArea.textFlow.interactionManager).applyLink( url, _target, extendToOverlappingLinks);        
    So why is this happening ?
    Thanks

    Example in http://blog.flexexamples.com/2009/06/28/styling-hyperlinks-in-a-textfl ow-object-in-flex-4/
    You can copy the code below, which runs correctly.
    <?xml version="1.0" encoding="utf-8"?>
    <!-- http://blog.flexexamples.com/2009/06/28/styling-hyperlinks-in-a-textflow-object-in-flex-4/ -->
    <s:Application name="Spark_TextArea_textFlow_linkHoverFormat_test"
                   xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/halo">
        <fx:Script>
            <![CDATA[
                import flashx.textLayout.conversion.TextConverter;
                import flashx.textLayout.elements.TextFlow;
                [Bindable]
                var markup:String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
        "<TextFlow xmlns=\"http://ns.adobe.com/textLayout/2008\" whiteSpaceCollapse=\"preserve\" fontSize=\"16\" paragraphSpaceAfter=\"15\" paddingTop=\"4\" paddingLeft=\"4\">"+
            "<linkNormalFormat color=\"#00ff00\" textDecoration=\"underline\" />"+
            "<linkHoverFormat color=\"#ff0000\" textDecoration=\"underline\" />"+
            "<linkActiveFormat color=\"#ff00ff\" textDecoration=\"underline\" />"+
            "<format id=\"code\" backgroundColor=\"#000000\" backgroundAlpha=\"0.1\" fontFamily=\"_typewriter\" />"+
            "<p fontWeight=\"bold\">The following excerpt is from <a href=\"http://blog.flexexamples.com/\" target=\"_self\">Flex Examples</a>:</p>"+
            "<p>The following example shows how you can import a TextFlow object from an XML object in Flex 4 by using the static <span format=\"code\">TextFlowUtil.importFromXML()</span> method.</p>"+
            "<p>For more information, see <a href=\"http://blog.flexexamples.com/2009/06/25/importing-a-text-flow-from-an-xml-object-in-flex-4 /\">\"Importing a text flow from an XML object in Flex 4\"</a>.</p>"+
        "</TextFlow>";
                [Bindable]
                var tf:TextFlow = TextConverter.importToFlow(markup,TextConverter.TEXT_LAYOUT_FORMAT);
            ]]>
        </fx:Script>
        <s:TextArea id="txtArea"
                    textFlow="{tf}"
                    editable="false"
                    width="400"
                    horizontalCenter="0"
                    verticalCenter="0" />
    </s:Application>
    PS:
    I used TextConverter.importToFlow instead of TextFlowUtil.importFromString, because the former one is a tlf function under our controls, while the latter one is a flex function. I'm accustomed to take advantage of our own functions.

  • Making clickable links in a TextArea?

    Hi there,
    I made a TextArea where several URLs are being displayed in the form (http://www.url.com)...does anybody know if it is possible to make these hyperlinks? So the user can click on whichever one they want and view it in their primary browser?
    If someone can help me here, I'd reallly appreciate it. Would be great.
    Thanks in advance,
    -jtk

    I made a TextArea where several URLs are being
    displayed in the form (http://www.url.com)...does
    anybody know if it is possible to make these
    hyperlinks? So the user can click on whichever one
    they want and view it in their primary browser?instead of using a TextArea you could use a Jlist
    then add a mouse_clicked event and then call
    Runtime.getRuntime().exec("cmd /c start "+tempString);
    where tempString is your URL in the list
    chidychi

  • Asfunction in textArea?

    I have a textArea component filled with a paragraph of copy.
    I'd like one word to link to another frame in my Flash file
    (gotoandStop function, I'm thinking). Do I place my "var..." code
    at the top of the paragraph, or as another action? The text is
    called into the textArea box via an action. I think I need to use
    an asfunction, but am unsure. It seems like it should be a pretty
    easy thing – hyperlink to another place in my Flash
    presentation by clicking on a word? Why does it seem so hard? You
    can tell I'm a designer, not a programmer, and all this
    actionscript stuff is confusing to me.

    any follow up to this? i am interested ...
    how can i include an MC or button inline within the HTML text
    of a TextArea component -- and also have that object link to an AS
    function? i want to have icons within the text of my TextArea that
    open pop-up windows within the Flash application (MC linkage).
    is this possible?
    and how is asfunction used?

  • Hyperlinks in HTML Widget?

    Hello,
    i embedded a textfield with scrollbar in iWeb by using the HTML Widget.
    the code is:
    <html>
    <head>
    <title>Textfeld</title>
    </head>
    <body>
    <textarea cols="50" rows="10" readonly style="resize: none";>
    Text
    </textarea>
    </body>
    </html>
    Can i enhance i Hyperlink to the text?
    Thanks

    Thanks,
    i still don't understand how to add he link. Can you please show me on the sample? I would like to have the dates as a link to a referring text file:
    <html>
    <head>
    <title>Textfeld</title>
    </head>
    <body>
    <textarea cols="100" rows="30" readonly style="resize: none";>
    12. August 2010
    „Der Bürgerbrief“ - Seit 4 Jahren umfassende Information aus erster
    Hand
    29.Juli 2010
    „Wenn die Stadt die Zuschüsse für Badisches Staatstheater und ZKM kürzen, fehlt den Einrichtungen das Geld doppelt“
    </textarea>
    </body>
    </html>

  • Mouse Cursor over Hyperlink

    How can i change the mouse cursor when the user is floating over a hyperlink, i am currently using a Hyperlink listener:
    new HyperlinkListener() {
                        public void hyperlinkUpdate(HyperlinkEvent e)
                             if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                                  getThePage(e.getURL().toString());
                   }

    Here is a small example demonstrating how to change the cursor in a TextArea:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class TxtDemo extends Frame implements ActionListener {
        TextField textField;
        TextArea textArea;
        String newline;
        public static void main(String[] args) {
            Frame F=new TxtDemo("Test Window");
            F.pack();
            F.setVisible(true);
            F.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                   System.exit(0);
        TxtDemo(String title) {
            super(title);
            textField = new TextField(20);
            textArea = new TextArea(5, 20);
            textArea.setEditable(false);
            textArea.setCursor (Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));  // see here
            GridBagLayout gridBag = new GridBagLayout();
            setLayout(gridBag);
            GridBagConstraints c = new GridBagConstraints();
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.fill = GridBagConstraints.HORIZONTAL;
            gridBag.setConstraints(textField, c);
            add(textField);
            c.fill = GridBagConstraints.BOTH;
            c.weightx = 1.0;
            c.weighty = 1.0;
            gridBag.setConstraints(textArea, c);
            add(textArea);
            textField.addActionListener(this);
            newline = System.getProperty("line.separator");
        public void actionPerformed(ActionEvent evt) {
            String text = textField.getText();
            textArea.append(text + newline);
            textField.selectAll();
    }Hope this helps..
    ;o)
    V.V.

  • Excel & Hyperlinking with Sharepoint

    I have a tracking document in Excel that has each entry linked to another place on Sharepoint to locate files and intranet articles. There are no formulas or other complex entries....just text and hyperlinks.
    If I open the Excel file in Sharepoint and edit it there, we have no issues.
    If I download the Excel file to my desktop...all links to other files are broken (the intranet file links remain active). When I try to access the link I receive a pop up window that states, "Cannot open the specified file."
    This is a file accessed by multiple people and used as a resource, there are well over 100 linked entries and the group would like to be able to use the file on their desktops.
    I have already found and unchecked the "Update Links on Save" option. This now allows me to download the file to the desktop, have no access to the links, and then upload it where I can then access the links again.
    Is there any way to preserve the links so they can be accessed on the desktop?
    Software Specs
    Windows 7
    Office 2010
    Explorer 8
    Thank you,
    Christine

    The links are absolute. All links are to our internal team site or to our intranet. The intranet links aren't affected.
    This wasn't an issue before the company upgraded us to Windows 7/Office 2010.
    The links are established (right click, select Hyperlink, copy/paste from browser) while the Excel file is on the desktop and all work fine there.  The Excel file is then uploaded to Sharepoint where the links continue to work. When the Excel file is
    downloaded to the desktop again...all links are broken. If I re-upload it to Sharepoint though, it is fine.
    I double checked the actual link. It reads the same on the desktop initially as it does on Sharepoint. When the file is downloaded to the desktop again it seems to be missing the first half of it. What function could be editing the link?
    Christine

  • A problem with hyperlinks in my Interactive PDF on smartphones...

    I hope someone can help...  I exported both an interactive and for print PDF from inDesign.  When I view the PDFs on my pc the hyperlinks that I've made in the document work perfectly fine.  When I view the PDFs on my smartphone, the hyperlinks don't work.  I've gone through many forums to make sure all my settings were correct and have tried many different things to try to get them to work, but still no luck.  Has anyone come across this issue?  Is there any way to get these hyperlinks to work on a smartphone?

    Interactive PDFs on mobile devices are nothing short of a crapshoot.
    The readers are hit or miss and the better ones require payment.
    I wish I had better news for you but right now, that’s the way it is.
    Bob

  • Report navigation after creating hyperlink

    Hi,
    I am using Webi rich clinet XI R3.1. I have one main report with six dashboards and associated detailed reports. I created hyperlink for each of the dashboard and linked to detailed report in infoview.
    If i need to see main report i've to close this detailed report.Now how can i make the detailed report open in same window and navigate forward and backward to the main report instead of closing.
    I would appreciate if some one could provide any work around available if possible atleast.
    Thanks,
    Eswar

    Hi
    Create two links one Back and one Next in each report.
    Drag two free standing cells in the report and use opendocument syntax to create the links.
    The thread Re: Hyperlink Back functionality may give an idea.
    Regards

  • Questions on the features of a textarea.

    Hi experts,
    I am working on Documaker 12.0.1. I have some doubt related to the feature of a textarea mentioned below. Could you please put a light on it ?
    _1. Sizing_
         a- Can grow and shrink
         b- Can span pages
         c- Must fit on page
         d- Suppress variable lines
         e- Adjust top line
    _2.Default (fonts)_
         a- Tab stops
    I am having some problem while creating a fap. I have 2 textareas in a fap and separated by some space, when I am seeing the output the whole fap is going to second page, although it is having enough space to print in the first page itself. For some case when I am unchecking the ADJUST TOP LINE and checking CAN GROW AND SHRINK, its coming in first page. fap is auto sized also. When I am minimizing the space between two textareas to print in first page, its overlapping. Please let me know if you need any more information..
    Thanks,
    Bikas Ranjan

    You mention multiple options that can affect the result in numerous ways. For instance, 'Must fit' means that the text area must fit on a page if it can. So even with the can span turned on, the text might move as an entirety to the next page if it can't stay as a whole on the first page.
    Also note that with multiple text areas on a page, only the one text area that is formatting is allowed to split during that format. That means if you put two text areas one above the other and then make the top one grow, the bottom text area is "pushed". And if it encounters the bottom of the page, that text area will go to the next page - even if you had the split option on that one too. This behavior is not normally a problem when you consider that sections are mapped from top to bottom, but if you are using a different order or unusal sized items, it can get in the way.

Maybe you are looking for

  • HT201413 suddenly itunes will not open and I get a message that the "Data Execution Prevention" is blocking itunes from opening....why????

    itunes will not open and I get a message that the "Data Execution Prevention (DEP)" feature in Windows is preventing it from opening. (this is after I've been using itunes for years???? If I try to manually deselect itunes from the DEP filter, of cou

  • ITunes 7.0 ONLY recognizes nano in disk mode

    Hi All, This little problem of mine has been driving me nuts for the past 2 days. I recently got an ipod nano as a gift (not the second gen) and wanted to try it out. So I installed the latest iTunes 7.0 (and rebooted...), charged the nano to full ba

  • How to make Aperture use new drive

    Hi I recently bought a new 3TB HDD to replace my 1TB drive which was nearly full. How do I copy my existing files across and make Aperture continue to read them from its database? Regards Mark

  • False Ringtones and Missing iTunes Money

    I bought an album off iTunes a few days ago. I was planning on making a few of the songs ringtones; all of them had the little 'bell' next to them. Now, when I go back to make the ringtones, it says I can't (it doesn't have the little bell, and it sa

  • No extensions in Safari 5 preferences .

    I just installed Safari 5 and there isn't an extensions tab in the preference window. I tried re-installing it which didn't help. I also tried installing an extension to see if that would somehow enable the feature. It told me to turn extensions on i