Local hyperlink in JEditorPane

I set a HTML page from String variable to JEditorPane. I;ve got som hyperlinks to this page like
<A NAME="AAAAA">
Link
I need to handle such a link. I set editable to false and implemented hyperlink listener, but event returns null URL when calling getURL() and I do not know how to handle this links. Can anyone help ??? I want to navigate through fragment of this page.

If you don't want to have to fool around with the HyperlinkListener, just add the normal <BASE> tag to your HTML file. The <BASE> tag has the following syntax:
<BASE HREF="baseURL" TARGET="WindowName" >
The TARGET portion is optional!
Theoretically, the JEditorPane should be smart enough to look for the link from the same place where the original HTML file is loaded from but apparently there is a bug somewhere that prevents it from doing that.
;o)
V.V.

Similar Messages

  • Local HyperLinks in JEditorPane....

    Hello,
    I am having a JEditorPane with contents as HTML file.. HTML file has many local links [ <a href=#100> </a> .... < a name=100></a> ]. EditorPane setEditable() is false. I have implemented HyperlinkListener to JEditorPane... but evt.getURL() returns "null" value when evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED. So JEditorPane.setPage(URL) is not working...
    evt.getDescription() return value as "#100". I am using JDK1.3.1. How can I solve this problem ?
    thanks,
    reji

    You have to set ID attribute instead of name for destination tag.
    Try this
    best regards
    Stas
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import javax.swing.event.*;
    public class Test
    JFrame frame;
    JEditorPane ta;
    public static void main(String args[])
    new Test();
    public Test()
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ta = new JEditorPane();
    ta.setEditorKit(new HTMLEditorKit());
    ta.setEditable(false);
    HyperlinkListener lst=new HyperlinkListener() {
    public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) {
    String descr=e.getDescription();
    if (descr.length()>0) {
    descr=descr.substring(1);
    HTMLDocument doc=(HTMLDocument)ta.getDocument();
    Element text=doc.getElement(descr);
    ta.setCaretPosition(text.getStartOffset());
    ta.addHyperlinkListener(lst);
    ta.setText("<HTML><BODY><A HREF=#100>test</A><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><A href='' ID=100>100</A></BODY></HTML>");
    JScrollPane scroll=new JScrollPane(ta);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(scroll,BorderLayout.CENTER);
    frame.setSize(300,200);
    frame.setVisible(true);

  • Space after hyperlink in JEditorPane

    Hi all!
    I am displaying an html document in a JEditorPane, which has some hyperlinks. Everything is wotking, except that all the hyperlinks have an extra space after the text which is underlined and is a part of the hyperlink.
    I saw this problem in the bug database but marked as closed. However I still have this problem using jdk 1.4.1.
    http://developer.java.sun.com/developer/bugParade/bugs/4303958.html
    Thanks in advance for your help!

    I'm sorry but I posted this by mistake. The topic is duplicated, but the other one has the subject corrected and has duke dollars assigned.

  • How do i set multiple line with hyperlink in JEditorPane?

    hi all,
    i have a critical question where i have a JEditorPane component which it display the hyperlink. the problem occur when the display text of the hyperlink if it is too long, i need to truncate it into multiple line like "ABCDEF" to make it "AB<br>CD<BR>F". the hyperlink work only if the display text is not truncate to multiple line, it display nothing at all if i try to truncate them into multiple line.
    anyone? thanks and regards

    At the point you wish to change to two columns, Insert > Columns and then in the Layout Inspector, select the number of columns. After the insertion point, you will also need to insert another Column Change to return the following paragraphs to single column.
    Then Select the text to be bulleted and in the Text Inspector > List tab select the type of bullets.
    Note: This creates two columns that flow together. This can be tricky if you add any text later.
    If you wish to ensure alignment, create a two column text table and remove the lines with the Graphic Inspector > Lines > No Lines option and insert your text in each column and apply the bullets as above.
    This will create a text box - you then need to ensure it moves with the text by electing "Object Moves With Text" in the Wrpa Inspector.
    Message was edited by: bwfromspring hill

  • Problem with Hyperlink  in JEditorPane!!

    hi all!
    I have some problem.
    I create html page with hyperlink to myProgram.jar and when i open this html page in JEditorPane and click on hyperlink i have the some text but my program don't run.
    How write HyperlinkListener for run the my program and setUrl for open other html pages.
    thanks!

    In the future, Swing related questions should be posted in the Swing forum.
    But, there is no need to repost the question because you can just read the JEditorPane API to find an example of how to write a HyperlinkListener.

  • Hyperlink in JEditorPane URGENT

    I have encountered a problem regarding showing the html in JEditorPane(written under JApplet), since in the html code, there are some hyperlink which link to other html page. I can't link those page. Since I am not directly read the html from a file. I am passing those html code from the data I get from cgi and directly to JEditorPane. Anyone please help me solve this problem?
    Thank you..

    If you don't want to have to fool around with the HyperlinkListener, just add the normal <BASE> tag to your HTML file. The <BASE> tag has the following syntax:
    <BASE HREF="baseURL" TARGET="WindowName" >
    The TARGET portion is optional!
    Theoretically, the JEditorPane should be smart enough to look for the link from the same place where the original HTML file is loaded from but apparently there is a bug somewhere that prevents it from doing that.
    ;o)
    V.V.

  • S�ace after hyperlink in JEditorPane

    Hi all!
    I am displaying an html document in a JEditorPane, which has some hyperlinks. Everything is wotking, except that all the hyperlinks have an extra space after the text which is underlined and is a part of the hyperlink.
    I saw this problem in the bug database but marked as closed. However I still have this problem using jdk 1.4.1.
    http://developer.java.sun.com/developer/bugParade/bugs/4303958.html
    Thanks in advance for your help!

    I'm sorry but I posted this by mistake. The topic is duplicated, but the other one has the subject corrected and has duke dollars assigned.

  • Problem with hyperlink when JEditorPane in JDialog

    This following code works great:
    import javax.swing.*;
    import java.awt.event.ActionEvent;
    * Created by IntelliJ IDEA.
    * User: ilie
    * Date: Mar 31, 2005
    * Time: 1:21:28 PM
    * To change this template use File | Settings | File Templates.
    public class Test extends JFrame
        public Test() throws Exception
            JEditorPane pane = new JEditorPane( );
            pane.setEditable( false );
            pane.setContentType( "text/html");
            pane.setText( "<html><a href=''>a</a>");
            getContentPane().add( pane );
            pack();
            setVisible( true );
        public static void main( String args[]) throws Exception
            new Test();
    }Now... if I change the JFrame to JDialog, when I move the mouse over the links the cursor does not change anymore to a hand.
    Is this a bug? I think I do everything right.
    Thank you!

    This code here... also does not work :(
    import javax.swing.*;
    import java.awt.*;
    public class Test extends JDialog
        public Test() throws Exception
            JLabel label = new JLabel( "Boo" );
            label.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR) ) ;
            getContentPane().add( label );
            pack();
            setVisible( true );
        public static void main( String args[]) throws Exception
            new Test();
    }

  • How can a local Hyperlink be integrated into a Fixed Layout ePub

    How can I hyperlink within a book file a table of content (NOT the navigational from the iBook App)  and the index references.
    See screenshots.

    Yes, I had it all checked. I wonder why the CC does not show the Adobe Indesign CC 2014.1 as with Muse and Dreamweaver. It just shows Adobe Indesign CC 2014. How can I make sure the newer Version is really downloaded?

  • Hyperlink and JEditorPane again

    Hi there,
    i know this has been handled a few times but that doesn�t helped me much...
    so i ask it again.
    i want to write a really basic HyperlinkListener, but it does not work.
    heres my code
    HyperlinkListener myListener = new HyperlinkListener()
      public void hyperlinkUpdate(HyperlinkEvent he)
        try
          if(he.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
            editorPane.setPage(he.getURL() );
        catch(IOException ioe)
          System.out.println(ioe);
          ioe.printStackTrace();
    };why does it not work?
    theres no exception, if there would be one i would see in System.out...
    any ideas?
    thx anyway
    cu Errraddicator

    HyperlinkListener works on read-only JEditorPane's.
    Look at the documentation: setEditable(false) has to be set.

  • Problem in hyperlink

    Hello
    I have created an hyperlink in JEditorPane. Hyper link will only work after you set the editor Editable to false. I have done so. But after
    that I cannot type any text in the pane as I have set the Editable to false.
    Can you please provide me the solution how to set the Editable to true.
    m_editor.setEditable(false);
    carrot.setBlinkRate(normalBlinkRate);
    carrot.setVisible(true);
    m_editor.grabFocus();
    //Action listioner for hyper link
    m_editor.addHyperlinkListener(new HyperlinkListener(){
    public void hyperlinkUpdate(HyperlinkEvent e) {
    if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
    ctrl.setNodeSelection(UIDNameHash.hash.get(e.getDescription()));
    m_editor.grabFocus();
    If I set the Editable to true after the listener, the hyper link is not working.
    Thank you in adance

    If I set the Editable to true after the listener, the hyper link is not working.Thats the way it was designed. Thats the way it works in all other applications.
    If you want it to work on on an editable editoir pane you will have to write all the code yourself.

  • Creating links to files

    I want to create a local hyperlink, so to speak, to link scans of receipts to an accounting program - Money 2.5.4, by Jumpsoft. I've scanned the receipts in small .jpgs and would like to link each transaction to its receipt.
    Any ideas on how I might do this? Am I even in the right forum?
    Thanks in advance.
    W Baker

    Let me add that these proposed links wouldn't be in some accounting field or spreadsheet cell, just in plain text in a "comment" area.
    Thanks.

  • Highlight words in html page set on editorpane

    hi everyone
    please help me quickely
    I have java application
    I could display html with hyperlinks on Jeditorpane
    but my problem is that
    i want to get specific word in this page
    to highlight it and display this html page with highlighted word
    can anyone solve my problem?
    thanks

    Thank you for the reply. I can understand if it was changed intentionally for some reason, though I can't think what that reason might be.
    I know that it definitely works fine in Firefox 21, and changed in Firefox22 and 23 (I tested the beta, aurora and nightly versions and the behavior is the same as 22 & 23 there too)
    I have attached two screen shots of what it looks like when I open a new tab on firefox 21 vs firefox 23. When I use a completely new profile (or even on a different operating system), the behavior is consistent as well, so I think this is definitely something that changed from 22 onwards. (link titles changed)
    I should add, this quite drastically changes the way I use firefox, because I am no longer able to use middle click to paste URLs or search terms into the URL bar. I might select the out put of an error message in a terminal and then just middle click to paste in the bar and hit enter to go from there.

  • How to insert hyperlinks in RTF document shown in JEditorPane?

    This is a compound question so bear with me on this one :)
    What I need is to insert an hyperlink in a JEditorPane; Store it as RTF code; Retrieve it; Show it and click on it to go the the destination.
    1) So, first question, is there some method to automatically add the hyperlink and will it be saved in RTF with RTFEditorKit? (I'm actually using AdvancedRTFEditorKit but an answer to either will be enough)
    2) I tried a method that adds what appears as a link but the document that is stored doesn't have the necessary RTF codes, only the formatting that makes it look like a link. I also checked the actual RTF codes I'd need to add and they seem easy to do. So, is there a way to add the actual underlying RTF codes to the document while it's in the JEditorPane?
    I know the question(s) isn't too specific, if you can shed some light over the whole thing and point me in the right direction, it'd be great!

    Just a follow up to my own question. I found a way to answer my question 2) and I'm now storing the rtf code for hyperlinks. Now, when I show the document in JEditorPane with RTFEditorKit, I get the name of the hyperlink with no formatting indicating that it's a hyperlink.
    Example. The link "http://www.google.com" with the name "Google", only shows "Google" in plain text.
    Is it because the components I'm using don't support hyperlinks from RTF files even though they're supported from HTML files?
    Is there any way you can see this working? Is it possible to include something inside the JEditorPane that the user can click, instead of the hyperlink?

  • HT5071 Is it possible to call a locally installed ibook from a hyperlink? What about to a bookmark?

    Is it possible to call a locally installed ibook from a hyperlink? What about to a bookmarked page?
    I have 2 questions..
    1. Can I send a link via email that when launched will open an ibook that has already been downloaded to the bookshelf?
    2. If question 1 is possible, can I take it a step further and call a bookmark, i.e. chapter 3.
    Our company has it's own appstore and I want to send out links to sections of the ibooks using bookmarks or at the very least take them to the start of the ibook.
    I don't need to give them a link to install the ibook as they already have it installed.
    Any help would be much appreciated.
    Chris.

    That would be cool, but it's not possible. The ibook is not accessible by URL in the user's bookshelf.

Maybe you are looking for

  • Need a way to speed up the initial population of the entire BDB

    We are transitioning an existing production system from flat file based DB to BDB. On the day we switch to BDB, we have to populate the BDB for more than 2 Million users. Once we populate, BDB serves the data vary adequately. However, the initial pop

  • Swapping a library drive--did it on a PC, how on a Mac?

    I've made the switch from PC to Mac and am very happy overall. However, there's one thing I used to be ablet to do on my PC that I can't on my Mac. On my PC, my music drive was \\mynasdrive\music which I mapped to "M:". When I travelled, I could stil

  • SQL convet .csv

    PROCEDURE PROC_EXCEL (t_file varchar2, t_sql varchar2) IS connection_id EXEC_SQL.CONNTYPE default exec_sql.default_connection; cursorID EXEC_SQL.CURSTYPE; nIgn number; columnValue varchar2(10000); ncols number; sep varchar2(1); colName varchar2(1000)

  • Flash button dreamweaver cs3

    Hello i have a problem with DW cs3 with flash buttons.when im trying to add a new flash button then i got always that message"button1.swf" is an invalid file name.please enter a different name.im trying a new name but it's same..plz can i have some h

  • Passing DNS server addresses through DHCP?

    I'm setting up NAT & DHCP (both as a DHCP client & DHCP server) on a 2621. Since the DNS server address(es) are received on the router's interface configured as a DHCP client, is there a way to pass these (possibly dynamic) address(es) on the interna