aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes control JTextPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "control JTextPane" Watch "control JTextPane" New topic
Author

control JTextPane

A Wu
Greenhorn

Joined: Jan 14, 2004
Posts: 7
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.
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100

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!


An egg is a chicken's house!
A Wu
Greenhorn

Joined: Jan 14, 2004
Posts: 7
thanks Jason! your suggestions helped a lot !
 
 
subject: control JTextPane