File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Problem inserting text after hyperlink  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem inserting text after hyperlink  " Watch "Problem inserting text after hyperlink  " New topic
Author

Problem inserting text after hyperlink

Pinik Tilli
Greenhorn

Joined: Jul 19, 2006
Posts: 19
Hallo,

I have problem in inserting text after hyperlink in JEditorPane. I have created a button to insert the link.

Steps:

1.Select the button.
2.Slect a node in the tree
3.release the button

then the hyperlink is created in the editor pane with the node's name. After inserting the hyperlink I cannot write text after the created hyperlink as the text newly enterred after the hyperlink also gets included in the hyperlink. I need your help to set the style so that I can enter any text after the hyper link as well.

int editcurrentSel = m_editor.getCaretPosition();
int p = m_editor.getCaretPosition();
AttributeSet attr = m_doc.getCharacterElement(p).getAttributes();

// First, setup the href attribute for <A> tag.
SimpleAttributeSet hrefAttr = new SimpleAttributeSet();
hrefAttr.addAttribute(HTML.Attribute.HREF, objectID);


// Second, setup the <A> tag
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTML.Tag.A, hrefAttr);

m_doc.insertString(m_editor.getCaretPosition(),objectName, attr);
m_doc.setCharacterAttributes(editcurrentSel,objectName.length(), attrs, false);

Thank you in advance
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 865
    
    1
I'm not sure exactly what you are asking, but if you are having
trouble with new text inheriting attributes of previous text,
you can try getInputAttributes().removeAttribute(...).


bitguru blog
 
jQuery in Action, 2nd edition
 
subject: Problem inserting text after hyperlink