I can't add simple HTML link to HTMLDocument in jEditorPane

h5. How to construct a link to make it work?
HTMLDocument doc = (HTMLDocument) jEditorPane.getDocument();
String link = dialogSlownikEkranow.getLink();
SimpleAttributeSet tag = new SimpleAttributeSet();
SimpleAttributeSet attrs = new SimpleAttributeSet();
tag.addAttribute(HTML.Tag.A, attrs);
attrs.addAttribute(HTML.Attribute.HREF, link);
+try {+
+ doc.insertString(jEditorPane.getCaretPosition(), "some link", tag);+
+} catch (BadLocationException e1) {+
+ e1.printStackTrace();+
+}+
h5. As a result I get
<+a href="\mw\client\cd\plytacd.html"><p></a>+
h5. but I require something like
<+a href="\mw\client\cd\plytacd.html">some link</a>+

Hi,
nirgal wrote:
h5. How to construct a link to make it work?
HTMLDocument doc = (HTMLDocument) jEditorPane.getDocument();
SimpleAttributeSet tag = new SimpleAttributeSet();
SimpleAttributeSet attrs = new SimpleAttributeSet();
tag.addAttribute(HTML.Tag.A, attrs);
attrs.addAttribute(HTML.Attribute.HREF, link);
I don't believe that SimpleAttributeSet is right for HTMLDocument. In your code, you regard a HTML.Tag as a AttributeSet. Apparently this is not the absolute truth. May be I'm wrong, then one may correct me.
My suggest�on is to use string concatenation to make the HTML for the link and then use HTMLEditorKit.read to put this HTML into the HTMLDocument on caret position.
import java.awt.*;
import javax.swing.*;
import java.io.*;
import javax.swing.text.*;
public class JEditorPaneSample {
  private static void createAndShowGUI() {
    JFrame frame = new JFrame("FrameDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JEditorPane jeditorpane = new JEditorPane();
    jeditorpane.setContentType("text/html");
    jeditorpane.setText("<p>Hello World</p>");
//insert a link on caret position
String link = "mw/client/cd/plytacd.html";
String htmlstring = "<a href=\"";
htmlstring += link + "\">";
htmlstring += "some link" + "</a>";
try {
  jeditorpane.getEditorKit().read(new StringReader(htmlstring), jeditorpane.getDocument(), jeditorpane.getCaretPosition());
} catch (BadLocationException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
    System.out.println(jeditorpane.getText());
    frame.getContentPane().add(jeditorpane, BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
  public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        createAndShowGUI();
}greetings
Axel

Similar Messages

  • Can I add a text link to another place in a Pages v5 file?

    Simple question:
    Can I add a text link to another place in a Pages v5 file?
    My client would like to include a visible, inline Table of Contents in his ePub. Apple Pages v5 deletes the visible Table of Contents. Can I manually create a Table of Contents with clickable links to the appropriate chapters?

    Pages 5's greatest claim to fame is its general inability to do anything much, aka "simplification".
    So the answer is No! and because this is also Apple, You don't want to do that!
    Luckily however, should you still have Pages '09 in your Applications/iWork folder, you can use that instead.
    Peter

  • How can i add a new link to Portal favorites?

    Hi,
    I have created a portal application and configured it to a porta frame work page byy adding iViews and portal pages.
    I would like to display an iView as a link in the  portal favorites. I have added it to portal favorites as related link. But nothing is displayed in the portal favorites when i logged in as application user.
    How can i add a link to the created iView just like  the "DeveloperContent" link shown in portal favorites when we login as portal administrator?
    Your help and suggestions solicited...
    Best regards,
    Sudheesh

    Hi Sudheesh,
    The Related Links option is for Content Administrators to add links that they think will be useful for a certain page or iView...an end user can't add their own links to the Related Links iView. Also, you don't need Knowledge Management installed in the Portal for the Related Links iView to work. Also, Related Links will be available only on the pages/iViews that the Content Administrator has created them.
    Read more about Related Links here:
    http://help.sap.com/saphelp_nw04/helpdata/en/e3/1d37600aa111d7b84700047582c9f7/frameset.htm
    Portal Favorites is a nice option for end users to decide which iViews or pages they would like to be available from every Portal page.
    To open new iViews/pages in a new window, rather than in the current Content Area, adjust the Workprotect mode of the portal (either the user can do it for their preference or the Administrator can do it for everyone):
    http://help.sap.com/saphelp_nw04/helpdata/en/15/4b673e214ad112e10000000a11405a/frameset.htm

  • Can I add a topic link to a desktop layout sidebar tab?

    Hello,
    I'm currently working in Robohelp 10 and using a modified version of the desktop layout. We don't need the Glossary tab in the sidebar, so I'd like to replace it with a Videos tab instead. I was able to add a new tab to the sidebar without a problem, but I'm having difficulty figuring out where to go from here. Ideally, when users click on Videos, I'd like it to launch one of our topics that already lists all our current videos and includes links to them. Is it possible to do this? Or is my only option to manually add the video links to that tab's section in the Topic.slp HTML? I'd like to avoid this if possible, since it would mean maintaining the videos list in multiple locations within the help project.
    Thanks in advance,
    Alison

    The question is always how much time and effort you are willing to invest. The easy answer is that the tab in the sidebar does not load topics, or any other data for that matter. If you want this behaviour, you will have to create it yourself.
    It is possible to create a script to load the list of video's from a predetermined location. But if you want to get it from a topic, the script will have to be interesting as it will require a lot of parsing the topic to get the relevant data. An easier solution would be to maintain an XML with links and descriptions and read that. I offer consultancy for building precisely these kinds of solutions. Please PM me if you want to know more.
    Kind regards,
    Willam

  • Can i add a "print" link in standard KM iViews??

    Hi All,
    I have done some Portal development.
    I am new to KM.
      I have some doubts:
    1.       I want to develop custom News Component, Discussion Group & Discussions etc.. What perspective I should use? I mean, is it PDK? Or is there something else?
    2.       In a standard KM iView (for ex: in a news iView), can I add a link called print (say) to print the whole content in the iView? Or should I have to make a custom development for that.
                Please tell me what I should refer to. Any classes like IRoom, IDisscussionGroup etc..????
    Plz help me.
    <b>Regards,
    Sai Krishna.</b>

    Any ideas/solutions? Please do share.
    Sai.

  • Can I add a HTML code in adobe flash CS5 ?

    Hello ! I'm French
    I'm working in a flash template (like this one http://www.templatemonster.com/flash-templates/22075.html) and I would like add a HTML code. Could I ?
    If I can, where insert him ?
    Thank-you, have a good day, Jérôme.

    if your textfield has instance name tf, you can use:
    if actionscript 2:
    getURL ("mailto:[email protected]?subject=Flash Form&body="+tf.text);
    if actionscript 3:
    navigateToURL(new URLRequest("mailto:[email protected]?subject=Flash Form&body="+tf.text));

  • How can I add an HTML Element to a RowSetBrowser

    Hello,
    I am looking for any help on adding a HTML element such as a checkbox to every row that is returned to the RowSetBrowser. I am wanting to have the value on the checkbox be the primary key such as a logid, so that I can have a user select multiple rows, and then create a combined log that will be stored in the database as one record.
    Could anyone please let me know if you can add an HTML element to the RowSetBrowser.
    An answer would be greatly appreciated ASAP. If this cannot be done, I would like to go about it another way.
    Thank You,
    Jason

    The idea is the following:
    First you create a new attribute in the ViewObject, with the following information:
    In the definition of the new attribute, there are three things to consider:
    In the information "Attribute":
    - Name: RowChecked
    - Type: String
    - Selected in Query: Yes
    In the information "Updateable":
    - Updateable: Never
    In the information "Query Column":
    - Alias: RowChecked
    - Expression: '<input type="radio" name="recomendado" value="'||TableName.ColumName||'">Text to show'
    - Queriable: Yes
    Then in the jsp page you use the setDisplayAttributes method where you include the attributes to render, to show this attribute you have created. And if you need pass this information to another page, include a a HTML Form before the RowSetBrowser, and after the bean a button to submit the information and finally close the HTML Form.
    I hope this information can help you.

  • How can I add a twitter link to my mobile me website and how can I put up a link to my blog

    How can I add twitter to my website I tried following the instructions from twitter I could post a line of text which worked as a link but I could not get the twitter bird logo to appear.
    Also how can I find the address of my blog page. How can I set up  alink to my blog page.
    Thank you
    I am running snow leopard on a macbook 10.6.8

    Thank you. I could not find a way to reply to you I did not see the reply button. So I thought I had to just post it again.
    I only want to put up a twitter button on to my webpage. I have already put up the text from twitter on to my website and this link works [ I think}  but not the graphic of the button. I want to do the follow buttton which was not listed on the address above.
    I tried the address for my blog you suggested and it did not work.Will this address be on my website somewhere.
    Still confussed.

  • How do I add an html link/banner to a page in my flash website?

    I purchased a flash website template and am in the process of editing my main.fla file.  In order to get listed on an advertising website with a higher rating, I have to place a reciprocal link to them on my site.  However, I cannot figure out how to place an html link/banner on my site for other businesses.  If I paste the html code in a text box, all that shows up is the html code rather than the image and link it is meant to generate.  Please help!

    Flash only supports a small amount of html in text areas.  If what you re trying to include is within what it supports, then you assign the text to the textfield using the htmlText property of the TextField...
    tfield.htmlText = "<a href="...">link</a>"; // will display "link" as a link

  • Can Contribute add, delete, edit links in this photo gallery?

    I'm not having much luck getting Contribute CS4 to delete or add photos, with correct nav, to the gallery below.
    It takes them out, leaving a blank page, or adds them in, not linked to the buttons.  Replacing the photo with a new photo also gives a blank page.
    http://www.studioegraphics.com/photography/index.html
    This gallery lives in it's own folder and with it's links to next/previous neighbor .jpg files.
    How would I get Contribute to add a new photo into the set or delete a photo from the set, with correct navigation?

    Try deleting the iPhoto preference file, com.apple.iPhoto.plist, that resides in your User/Library/Preferences folder. Now try editing them again.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto (iPhoto.Library for iPhoto 5 and earlier) database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger or later), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 6 and 7 libraries and Tiger and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.≤br>
    Note: There now an Automator backup application for iPhoto 5 that will work with Tiger or Leopard.

  • Can I add an internal link in a Pages 5.5.2 Document

    In previous versions of Pages I could add a link from a word in my document to, say, a topic in a different place in the document. Either I've forgotten how to do it or the ability has gone away. Can someone help?

    Thank you for the (sad) information. When I try to open my document that I had already updated in v5 with v4.3 it says it can't be opened because the required index.xml file is missing. Any idea how to get around that?

  • How can I add social media linked icons to my mac mail signature in osx mountain lion?

    I've added png files to my signature and then hit command k and added a website to "link" each, however when i send the message the icons are there, but they don't "link", as in I can click on them and the png file just bounces back up.
    I am sure that Apple Mail has a way to do this, as every other carrier seems to have figured this out!
    Help!

    "a signature with my logo" - please explain.
    If I wanted a signature with a logo, I'd create an HTML document containing text and an embedded image. Adding, for example, facebook and twitter icons would be done in just the same way, by embedding their icons into the same HTML signature document.
    What's stopping you just adding more graphics?

  • How can I add document-internal links in Pages 5?

    I have a number of very large dicttionary documents (300+ pages) all of which have internal links. The internal links allow you to jump from one letter to another, so that, for example, if you're looking at words that begin with S, you can go to the A-Z letterboard at the beginning and end of the S section and immediately jump to any other section. I've also got links in the middle of the document leading to parts in the front matter (so, for example, a mention of the word "relative clause" will be linked to a section in the grammar discussing relative clauses). The nice thing is that these links would remain active when exported to .pdf, so when I shared them with others, the internal links continued to function. Each document has hundreds of these internal links. All of them appear to have been broken by the new version of Pages.
    Is there a way to create document internal links like the ones I used to use for Pages '09, or has this functionality been forever removed from Pages? If the latter, who do I scream at?

    Bookmarks have been removed along with 100 other features.
    You could post at Menu > Pages > Provide Pages Feedback but that is pointless in my experience
    Instead rate/review Pages 5 in the App Store where everyone can see it. In our local App Store, Pages 5.1 is back down to 2 stars with again 61% of users saying they hate it.
    Pages '09 should be in your Applications/iWork folder, use that instead.
    Peter

  • Can I add a document link to a Note in Mail?

    I know you can insert a URL link, but I wanted to link to a document or .pdf on my system within a Note in Mail. Thanks so much!
    -- Grace

    I just tried to drag and drop the document in the Note and it worked!

  • RoboHelp 8 - Can you add a download link inside a topic to download a Captivate demo?

    I want to give Users the option to actually download an SWF demo that I've created with Captivate 4 and imported into RoboHelp8. I don't know how to do this. The files are inside the RoboHelp project. I just don't know how to set up a download script. Has anyone ever done this before and if so what did you do to make it work.
    Thankds Deb.

    Hi there
    Any link to a SWF will likely result in the SWF opening in the viewer window. Probably it would be best to zip the SWF if you wish to allow downloading. The only other thing that comes to mind is to possibly instruct the user that they may right-click and choose to save the file.
    Cheers... Rick
    Helpful and Handy Links
    RoboHelp Wish Form/Bug Reporting Form
    Begin learning RoboHelp HTML 7 or 8 moments from now - $24.95!
    Adobe Certified RoboHelp HTML Training
    SorcererStone Blog
    RoboHelp eBooks

Maybe you are looking for

  • 8.0.5 on redhat 6.0 HELL!

    Hi I have just spent a weekend trying to get the above to work. I will admit that I am no unix guru or oracle dba, but I do have 5+ years tinkering in unix and 1 year with oracle. But this weekend has been hell. The installer is a joke and the proced

  • Save only if data changed...

    Hi all, I have a context node with a few attributes. The view has a save button, which saves data to database tables. I need to call the save function only if user has changed any data and not otherwise. How should I go about for it?? Is using the co

  • Startup disk application memory issue

    Brand new imac with solid state 250GB as startup (200 used) and 2TB as number 2. The force quit dialogue box keeps coming up asking me to quit applications (even when just running mail) saying i have no more space. 50 GB still available on the drive.

  • Custom PLUS panel anyone?

    Hi, I am trying to hold some model release information in some of my assets and thought it best to adhere to the PLUS standard.  However I am new to Custom Panels and am struggling to get it to work. Has anybody out there already created a custom pan

  • Re-downloading App wants to buy again.

    When I've already bought an app and then when I want to redownload it, I click on the Buy button but it gives me a warning that my account will be debited, it doesn't give me a message that I've already bought it and it will download for free. At fir