Win a copy of Terraform in Action this week in the Cloud 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

control JTextPane

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
few questions:
1. how do i select some text, provided i know the positions of start and end. i tried
jtextpane.select(pos1,pos2);
but it didnt mark the text, it only moved the caret to pos2.
2. how do i prevent a user from typing any text in the textpane? however i want him to be able to click on words in the textpane
summarizing the above two questions: my requirement is to select/mark a word on which the user clicks. any inputs on this would be appreciated.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1. how do i select some text, provided i know the positions of start and end. i tried
jtextpane.select(pos1,pos2);
but it didnt mark the text, it only moved the caret to pos2.


Well I haven't coded it, but if I understand, you want to hightlight text....correct?
If that's the case, check this out. It will help you greatly.
Highlighting Words in a JTextComponent


2. how do i prevent a user from typing any text in the textpane? however i want him to be able to click on words in the textpane


This sounds a like hyperlink effect?
If so, I know JEditorPane is often used for this by adding a HyperlinkListener. Maybe you can implement that with JTextPane. I'm not sure.
See if this helps. (Click on JEditorPane in the left frame.)
JEditorPane
Good Luck!
 
A Wu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Jason! your suggestions helped a lot !
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic