• Post Reply Bookmark Topic Watch Topic
  • New Topic

Make some words of a text clicable in a JTextPane  RSS feed

 
luca rossix
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,

i'm doing a spell checker, but i have a problem with a JTextPane.

I want to insert te checked text into a JTextPane where all the recognized wrong words have to be clickable like a button. When clikked (simple click) they should list all the possible correction into a JList just below the JTextPane.

Some idea on how to do it? Expecially what listener should i use?

EDIT: Offcourse the Jlist and the JTextPane are on the some jpanel on a jframe.
 
randy orton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
luca rossix wrote:Hello friends,

i'm doing a spell checker, but i have a problem with a JTextPane.

I want to insert te checked text into a JTextPane where all the recognized wrong words have to be clickable like a button. When clikked (simple click) they should list all the possible correction into a JList just below the JTextPane.

Some idea on how to do it? Expecially what listener should i use?

EDIT: Offcourse the Jlist and the JTextPane are on the some jpanel on a jframe.

hello ....
String matching can help you .You can do this by algorithms like rabin-karp,Naive etc.
rabin karp
Now you have to match your word.For eg. take word how ,all possible errors that can be made are o,w,ow.Use algorithms to match how.
Using JEditorPane can also help you.
 
Stanislav Lapitsky
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
luca rossix wrote:Hello friends,

i'm doing a spell checker, but i have a problem with a JTextPane.

I want to insert te checked text into a JTextPane where all the recognized wrong words have to be clickable like a button. When clikked (simple click) they should list all the possible correction into a JList just below the JTextPane.

Some idea on how to do it? Expecially what listener should i use?

EDIT: Offcourse the Jlist and the JTextPane are on the some jpanel on a jframe.


Use normal MouseListener to listen clicks. Then obtain offset of clicked point by viewToModel() method. Then use Utilities.getWordStart() getWordEnd() to detect bounds of the clicked word. The find somehow suggestions for the word and place them in the list.
 
luca rossix
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stanislav Lapitsky wrote:
luca rossix wrote:Hello friends,

i'm doing a spell checker, but i have a problem with a JTextPane.

I want to insert te checked text into a JTextPane where all the recognized wrong words have to be clickable like a button. When clikked (simple click) they should list all the possible correction into a JList just below the JTextPane.

Some idea on how to do it? Expecially what listener should i use?

EDIT: Offcourse the Jlist and the JTextPane are on the some jpanel on a jframe.


Use normal MouseListener to listen clicks. Then obtain offset of clicked point by viewToModel() method. Then use Utilities.getWordStart() getWordEnd() to detect bounds of the clicked word. The find somehow suggestions for the word and place them in the list.


Ive tried it but its kind "imprecise" because sometimes get the right word some other times take 2 or 3 words, i need a way to make clickable only the words that are mispelled. Maybe i should use another component or something like that?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!