JTextPane: Problem adding hyperlinks & images

Hi,
I have a problem and I just can't figure out how to solve it.
I need to implement a simple Editor for HTML files. Lucky for me, most of the functionality i need is already provided by swing, but i still need to add images and hyperlinks to my document. Especially, i need to be able to select some text, click on a button and turn it into a hyperlink. If an image is within the selected range, then the image should be included in the hyperlink as well (just as you would expect it to be).
Adding images works so far, using this code (i'll take care of actually loading the image when the rest works).
JEditorPane editor = getEditor( e );
HTMLDocument doc = (HTMLDocument) getStyledDocument( editor );
MutableAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute( StyleConstants.NameAttribute, HTML.Tag.IMG );
attr.addAttribute( HTML.Attribute.SRC, "p.gif" );
try {
     doc.insertString( editor.getCaretPosition(), " ", attr );
} catch (BadLocationException e1) {
     e1.printStackTrace();
}But when i try to do the same with HTML.Tag.A and HTML.Attribute.HREF, the selected text disappears from the code (it is still visible in the JTextPane, though) and is replaced by . I just don't seem to get the whole AttributeSet mechanism or which attributes need to be set to which values.
I have seriously been stuck on this stuff for over one day now, and went through half a million tutorials, but can't figure it out - and i can't imagine that it is that complicated to do something like that.
By the way, I don't care whether or not you can click on the link in the JTextPane. The whole application is just for editing purposes and the document's content will be uploaded to a webserver at a later point.
I hope there's somebody who can help me out here.
Thanks in advance,
ak87

Doesn't anyone have a hint for me here?

Similar Messages

  • Problems adding an image title?

    Hi,
    When I place an image in Muse I'm having problems adding an image title. When I Control click the image in Design view the choices I get at the bottom of the pop up menu are
    Edit original
    Edit Image Properties
    When I looked it up in help it tells me I should also see another item "Add Title" but I don't get that as a choice. When I click on "Edit Image Properties" I get a choice of Tooltips or Alt Text but no place for a title.
    Thanks,
    Bill

    This is the page
    http://www.adobekb.com/strategies_for_seo.html#addingmetadata
    To be clear when I right click on an image I only get the choice of "Edit Original" & "Edit Image Properties". When I click on "Edit Image Properties" I only get a choice of Tooltips or Alt Text, nothing for title
    Thanks,
    Bill
    Adding titles and alternative text to images
    After you place images on a page, you can access the Image Properties dialog box to set both a title and alternative text (also sometimes called alt text) that is assigned to the image.
    Here's a brief description of each property:
    Title: In many browsers, the title is displayed in addition to the image, typically as a tooltip that appears when a cursor hovers over it.
    Alternate text: If the image file cannot be shown, this text is displayed in place of the image. Alternate text is also used to describe images to visually impaired visitors using assistive technologies to access page content.
    It is ideal to set titles and alternative text for every site asset, to ensure that visitors have the best experience when navigating your site. Tooltips are helpful for including additional information about graphics and alternative text makes pages more accessible for screen readers that verbally present graphic content.
    To add titles and alternative text, follow these steps:
    1. Select a placed image.
    2. Right-click on the image and select Add Title or Add Alternative Text from the context menu that appears (see Figure 3).

  • Problem adding an image to the display list

    I'm trying to create a component to add images to a Panel (id=hbox). I seem to be loading the images successfully (because the trace statement works), but can't add them to the display.
    I'm using the following line of code, but getting an error:
    hbox.addChild(event.currentTarget)
    What am I doing wrong?
    Thank you!
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" backgroundAlpha=".5"   backgroundColor="0xffffff" creationComplete="init()"  >
        <mx:Script>
        <![CDATA[
        public function placeAnimals():void{
            for(var i:int=0; i<12;i++){
                var imageLoader:Loader = new Loader();
                var url:String = "images/animal"+i+".png";
                var urlReq:URLRequest = new URLRequest(url);
                imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
                imageLoader.x=50*i
                imageLoader.load(urlReq);       
                function imageLoaded(event:Event):void {
                    trace("Success="+event.currentTarget.url)
                   //hbox.addChild(event.currentTarget)
             public function init():void {
                 placeAnimals()
        ]]>
        </mx:Script>
        <mx:Panel  id="hbox"  height="200"   backgroundImage="images/smallWhitePanel.png"  borderStyle="none" />
    </mx:Canvas>

    You cannot add an image directly like that... why not dot the following
    var img:Image = new Image();
    img.source = url;
    this.addChild(img);
    hpefully it should work.. i'v neva seen image being added to the hbox like that... it will work only if you embed it / put it in source element..
    the following link should help you
    http://livedocs.adobe.com/flex/3/html/help.html?content=controls_16.html

  • Problem adding large images to albums

    What I want to do is view my images large, one at a time, and add them to various albums as I go. This used to work fine in v6 but now, zoom in Max and you can no longer select photos. It seems you can only select images once they are get about 320px wide or smaller.
    Any help as to how I can get this capability back?

    This is a known issue (discussed many times on this forum) with iPhoto '08 with no work around found yet.
    For now report to Apple - iPhoto menu ==> provide iPhoto feedback - and wait
    Larry Nebel

  • Problems adding logo/image.

    Hi,
    I have tried to create a logo/image for all pages within my application, however still receive the red cross broken image symbol.
    1) uploaded the image for my application using the shared components tool.
    2) Logo is set to: logo.gif
    logo attributes is: #APP_IMAGES#logo.gif
    any suggestions?

    Right click on broken image and copy link location (in firefox this is the option).
    Now place that link in URL bar to see if image is comming...
    Change the value in URL until you get the picture...look then what is wrong...
    This must lead to success...place the URL here so maybe there is something easy...
    P.S.
    Look in manuals what is WORKSPACE_IMAGES AND APP_IMAGES referencing. Try to place in images dir (/i/) that file and call it with #IMAGE_PREFIX#logo.gif (case sensitive call)-this should show logo.
    P.S. II
    Logo will be shown on every page. So it is not smart to put it in database. Better use #IMAGE_PREFIX# location on pure Apache file system.
    Hope this helps

  • Adding an image background

    I have problems adding an image (pattern) on my form. Can anyone give me some advice.

    Hi,
    We currently don't support background images. A work-around that can be used for HTML forms is to embed the form in a page hosted on your own website. If the embedded form is configured to be transparent the image behind the form will be visible.
    Please refer to the following FAQ for more information on the embed feature:
    http://forums.adobe.com/docs/DOC-1991
    Regards,
    Brian

  • Problem in displaying images one by one in JList

    I have a problem in displaying images one by one in Jlist. I want to show 100 images as a thumbnailview in jlist but it is talking too much time to show all the images after scalling 100 images to thumbnail view and making it into ImageIcon. So, i thought that it would be better way to show one by one after scaling it into thumnailview. But my renderer is getting calling after 100 images scaled down and setting into list. I have posted my code 2 days back but there is no reply.
    http://forum.java.sun.com/thread.jspa?threadID=789943
    I donno where i am missing in this code.
    Plz suggest me some solution for it.

    Where is the scaling done? In the ListCellRenderer? Regardless of where that is being done, I assume you are caching the scaled images after you scale them, right? If not, consider adding some sort of caching.
    This should do the trick...
    Rework your ListCellRenderer to check to see if a scaled version of the image is available. If not, start a thread to do the scaling and create an ImageIcon. In the meantime, while that thread is running, have the renderer return some sort of stock icon, like a little generic image icon. When the scaling thread completes, make a call to repaint() on the JList so the cell renderer gets re-asked for the icons. This time around, the renderer should notice that a scaled version (the ImageIcon) is available. Return that. So, this method doesn't guarantee that the images will be produced in order, 1...2...3..., but it will return images as they become available, and the overall JList rendering won't wait until all 100 are ready. If you want them returned in order, just do all of the scaling in a single thread and queue up the images to be scaled, in order.
    I hoped this helps. (If it does, please throw me some Duke Dollars.)

  • Problem using an image for a background

    Hi,
    My environment is Crystal Report 2008 SP2
    I am adding an image for a table header background in my report. The image is of type png.
    I use insert picture when I add it to the report. Up to there everything works fine.
    My problem happens when I try to draw lines on top of the image.
    All the lines that I draw stay underneath the image. Even though I move the image to the back and move the lines to the top.
    Any idea why?
    Is there something that I should do differently if I want to use an image as background?
    Thanks

    Please re-post if this is still an issue or purchase a case and have a dedicated support engineer work with you directly:
    http://store.businessobjects.com/store/bobjamer/DisplayProductByTypePage&parentCategoryID=&categoryID=11522300?resid=-Z5tUwoHAiwAAA8@NLgAAAAS&rests=1254701640551

  • Problems while accessing images outside the web document-root folder

    Our application runs on Oracle application server on Linux. Facing problems while accessing images outside the web document-root folder. This works with changes in global-web-application.xml by including the <virtual-directory> tag. The same change does not work when done on Linux machine. It is unable to find the image. Please help in resolving this issue.
    </locale-encoding-mapping>
    </locale-encoding-mapping-list>
    </web-app>
    <virtual-directory virtual-path="/img" real-path="/home/eposuat/" />
    </orion-web-app>
    Code in the jsp:
    <img width=700 height=700 src="/img/3.tif"></img>
    <img width=700 height=700 src="/img/WB.gif"></img>

    This is one of the least satisfactory aspects of site management in Dreamweaver, and several developers, including myself, have been pressuring the Dreamweaver team for some years to improve this. Who knows? They might eventually take notice.
    The only way to do this at the moment is to create two site definitions, one nested inside the other. Set up the site definition normally based on htdocs as your site root. Then create a new site definition based on site. Dreamweaver will nag you that it can cause problems, but it won't actually stop you from doing it. The only potential problem is with site synchronization.
    The problem with using site as the only basis for your site definition is that Dreamweaver automatically puts things like the Connections, Scripts, and other folders in the site root. So, everything ends up at the wrong level of the site hierarchy. Quite frankly, the whole thing is a bit of a pain. Dynamic site development was added to Dreamweaver only in version 6 (Dreamweaver MX), and no one had really thought through the need to store files outside the site root.

  • Problem creating several image maps (linking to different pdf files) RoboHelp 8

    Hi,
    I have a problem creating several image map hotspots (that link to different .pdf files), from the same image using RoboHelp 8 HTML (WebHelp project).
    After compiling, the first image map hotspot created, opens the .pdf file correctly.  Unfortunately, when clicking on the other image hotspots, I get an error " Cannot find file...<file path>... Make sure path or Internet address is correct".
    All the pdf documents are located in the same folder within the project.
    Can anyone help?

    Have you added the target files as baggage?
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Adding an image that a user can click.

    Hi
    Been programming java for nearly a year now and I was wondering if there was a way I can add images to a frame, which a user can then hover over to receive information of click to go to the next screen with sub information on it. Any help currently would be much appreciated.
    Gretna

    I was wondering if there was a way I can add images to a frameJLabel. http://java.sun.com/docs/books/tutorial/uiswing/components/label.html
    which a user can then hover over to receive informationtooltip. http://java.sun.com/docs/books/tutorial/uiswing/components/tooltip.html
    click to go to the next screen with sub information on itMouseListener. http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html
    Or use a JButton instead of a JLabel.
    http://java.sun.com/docs/books/tutorial/uiswing/components/button.html
    If the frame is to be a container for numerous "screens", consider giving it a CardLayout.
    http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html
    (Specific problems you have with adding the images would best be addressed to the Swing forum.)

  • Slideshow image resizing when adding new images

    I am creating a series of slideshows on multiple pages. I created one slide show using the "basic" slideshow and resized it to the dimensions and settings I wanted. I have many pictures all of different proportion, therefore, I selected the "fill frame proportionally" so they would all fit the dimension I set. I wanted to use this first slideshow as a template for all of the rest. I added images to this first slideshow with no problems. All of my different sized images scaled or cropped to fit within the dimension I set. The problem comes in when I do two things: 1) When I add other images of different dimensions to this same slideshow gallery, they come smaller that the intended dimensions I set previous. I check the setting and it is still on "fill frame proportionally" similar to the first batch of pictures. 2) The second issue is when copy this slideshow as a template to other pages. When I try to replace or add to the slideshow gallery, the images come in cropped or smaller rather than filling the frame. Again, the settings are still the same from my very first slideshow that worked just as i intended.
    I could resize all the images to all the same dimensions using another program like photoshop, but that is another step that is very tedious and it would seem that it should be something built into Muse.
    Is there a way around this?. Am I doing something wrong? Or is this just one of those glitches that happens with Muse? I appreciate any help that I can get.
    Thanks!

    Hi, I got it to work like this:
    Using background colours in Photoshop so that all sizes are the same in pixels. Then manually adjusting thumbnails by double-clicking on them so that a red square appears.
    Cheers,
    Elsemiek
    Op 26 dec. 2014, om 00:50 heeft MediaGraphics <[email protected]> het volgende geschreven:
    slideshow image resizing when adding new images
    created by MediaGraphics <https://forums.adobe.com/people/MediaGraphics> in Adobe Muse Bugs - View the full discussion <https://forums.adobe.com/message/7043933#7043933>
    Hi there Elsemiekagain,
    I had to fiddle around with my slide show to get it to work. That is, it worked at first, then went funky, and I had to fiddle. So much fiddling that I can't possibly know what actually made it start to work again.
    And to some degree, this is the way that I find Muse to be in general. That it requires finessing to get it to work as expected. This adds a good deal of time to every development project, though I am getting better at this with practice and experience.
    Most of it is not even things that could be easily put in words as instructions, as many are nanced. But in fairness, this version of Muse is a complete code re-write this year. So we do need to cut Adobe some slack, and give the team time to iron things out.
    If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/7043933#7043933 and clicking ‘Correct’ below the answer
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:
    Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/7043933#7043933
    To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following"
    Start a new discussion in Adobe Muse Bugs by email <mailto:[email protected]ftware.com> or at Adobe Community <https://forums.adobe.com/choose-container.jspa?contentType=1&containerType=14&container=47 59>
    For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624 <https://forums.adobe.com/thread/1516624>.

  • Problem with loading image to Applet.

    Hello. Im preety new to Java, and currently ive got problems with adding an image to my applet. I tried to make game, similar to Mario - a platform based one. I found a source code of something close to that, and wanted to test but i couldnt get images loading. Here's the code :
    Main class :
    package pl.wat.edu;
    import java.applet.*;
    import java.awt.*;
    public class Main extends Applet implements Runnable{
         Thread th;
         private final int speed = 15;
         private Level obecny_poziom;
         private Image dbImage;
         private Graphics dbg;
         MediaTracker mt = new MediaTracker(this);
         private Image ziemia1;
         @Override
         public void destroy() {
              // TODO Auto-generated method stub
              super.destroy();
         @Override
         public void init() {
              // TODO Auto-generated method stub
              super.init();
              setSize(stale.wielkosc_apletu_szerokosc, stale.wielkosc_apletu_wysokosc);
              //setBackground(Color.blue);
              //ziemia1 = getImage(getCodeBase(), "g1.GIF");
              obecny_poziom = new Pierwszy(this, this);
         @Override
         public void start() {
              // TODO Auto-generated method stub
              super.start();
              // create new thread
              th = new Thread (this);
              // start thread
              th.start ();
         @Override
         public void stop() {
              // TODO Auto-generated method stub
              super.stop();
              // Thread stop
              th.stop();
              th = null;
         public void run() {
              // TODO Auto-generated method stub
              while (true){
                   repaint();
                   try
                        Thread.sleep(speed);
                   catch (InterruptedException ex)
                   // do nothing
         @Override
         public void paint(Graphics arg0) {
              // TODO Auto-generated method stub
              super.paint(arg0);
              //arg0.drawImage(ziemia1,10,10,this);
              obecny_poziom.paintLevel(arg0);
         public void update (Graphics g)
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint(dbg);
              g.drawImage (dbImage, 0, 0, this);
    }and Level class that have draw levels from String rows :
    package pl.wat.edu;
    import java.applet.Applet;
    import java.awt.*;
    public abstract class Level {
         //private LevelElement [] elements;
         private WorldTile [] tiles;
         private WorldTile[][] tablica_kolizji;
         private Color [] colors;
         private Component parent;
         private int lewa_granica;
         private int prawa_granica;
         private int dlugosclevelu;
         private Image ziemia = null;
         private Image titi;
         private Applet applet;
         public abstract void resetLevel();
         public Level(Component parent, Applet applet) {
              super();
              this.parent = parent;
              this.applet = applet;
              ziemia = applet.getImage(applet.getCodeBase(), "g1.GIF");
         public void initializeLevel(String [] definitions){
              tablica_kolizji = new WorldTile [stale.dlugosclevela] [definitions[0].length()];
              lewa_granica = 0;
              prawa_granica = stale.wielkosc_apletu_szerokosc;
              int licznik_kratek = 0;
              for(int i=0; i<definitions.length; i++){
                   char [] definition_line = definitions.toCharArray();
                   for(int j=0; j<definition_line.length; j++){
                        if (definition_line[j] == ':')
                             tablica_kolizji[i][j] = null;
                        else if (definition_line[j]== 'g'){
                             Ziemia tile = new Ziemia(j*stale.szerokoscTile, i*stale.wysokoscTile, stale.ziemia_id, ziemia, parent);
                             tablica_kolizji[i][j] = tile;
                             licznik_kratek = 0;
              tiles = new WorldTile [licznik_kratek];
              int licznik = 0;
              for (int i = 0; i<tablica_kolizji.length; i++){
                   for(int j=0; j>tablica_kolizji[i].length; j++){
                        if (tablica_kolizji[i][j] != null){
                             tiles[licznik] = tablica_kolizji[i][j];
                             licznik++;
         public void paintLevel(Graphics g)
              try
                   // draw background
                   // draw all elements in elements array
                   for(int i=0; i<tiles.length; i++)
                        tiles[i].rysujTile(g);
              catch(Exception ex)
                   // do nothing
    Any ideas why this Image doesnt show up ?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    michali7x4s1 wrote:
    Thats a code i found somewhere, tried to check how some things work.Have you used exceptions before? If not, please read the sun tutorial on them as they are very very important. Also, whether this is your code or someone else's doesn't matter as it's yours now, and you would be best served by never throwing out exceptions as is done in this code. It's like driving with a blindfold on and then wondering why you struck the tree. It's always best to go through the tutorials to understand code before using it. If it were my project, I'd do it in Swing, not AWT. Fortunately Sun has a great tutorial on how to code in Swing, and I suggest you head there as well. Best of luck.

  • Adding hyperlinks to CP4 text

    Can anyone help with advise on how to add a hyperlink to text
    in Captivate 4. The hyperlinks from PowerPoint seem, to work, but I
    can't see a way to add a hyperlink in the text field to an external
    website.

    Hi
    Ok I was trying to record it, not working
    Make sure that you've copied or saved the pdf files are in the web site folder first
    1 insert text,
    2 with this text, create a fake link, blue and underline
    3 click on Click box in the tools box
    4 resize the click box over the fake link, I only keep the hint Type hint here (I deleted the 2 others) and I type Click on the link, in French Cliquez sur le lien
    5 click box is still selected, then in the left menu select Action tab
    6 In drop-down menu On success select Open url or file
    7 Click to browse, click on file or type the url
    8 Click on the drop down menu (arrow), click and select New so that way it will opens in a New browser window.
    When you export in swf
    You will have, at the end of the exportation, to copy paste manually the files in the web folder where is the swf file.
    Now we have a new problem. I didn't have this problem with all the projects published, but it happened once. Also, once on the server, the link would not open for that reason, see this blog. Still working on it. 
    http://sorcererstone.wordpress.com/2009/06/19/when-captivate-links-don t/
    sophie
    Date: Mon, 6 Sep 2010 19:21:40 -0600
    From: [email protected]
    To: [email protected]
    Subject: Adding hyperlinks to CP4 text
    Can someone provide me to the steps of adding hyperlinks
    to CP4?
    >

  • Hyperlink Images in IBA

    Is there any way to hyperlink images in IBA?  Currently we can only link text which is very frustrating when trying to promote other related titles using IBA linking to the iBookstore. 
    We have developed a work around...You create a text box over the image you want to link and you then fill it with whatever text, hyperlink the text and then make the text's opacity 0% making sure that the text is on top of the image.
    This is a frustrating work around.  I'm hoping for an update in IBA 3.0.

    That the standard method to link to an image in iBA.
    As always, tho, feel free to use the 'Provide iBooks Author Feedback' menu item for features you'd like added in the future, etc. 
    http://www.apple.com/feedback/ibooks-author.html

Maybe you are looking for