Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Problem inserting text after hyperlink  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Author
Posts: 974
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(...).
 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!