I too am having this issue. I think it may be something to do with the
dictionary I'm using (i.e. with it being on the disk). I'm using Jazzy to
check the text in one of the components I'm using in a Java application
I'm writing.
Do we have to write back out the dictionary when we're done, or
something? This seems a bit wrong, since the when I add words to the
dictionary, they are not preserved between Jazzy dialog instantiations -
even though I'm using the same dictionary object. So where does Jazzy
store these additional words?
I've taken a look at the source code too, and I'm having difficulty
determining where the add to dictionary code is. I can see there is a
method in the interface class SpellCheckEvent and that the
BasicSpellCheckEvent class implements this method, but I can't follow
what goes on then - it looks like two member variables are set, but I
don't understand where the actual replacement of the words happens.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, so now I've figured out where the word replacement happens. It
occurs in the 'fireAndHandleEvent' method of the SpellChecker class. It
will add the new word to the user dictionary. I assume it is then our
responsibility to save out this user dictionary somewhere when our
application exits if we want to save the additional words. However, this
doesn't explain why the words I add aren't remembered between
instantiations of the 'JTextComponentSpellChecker' class I use... more
probing required.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Right, I've figured out what's going on. It would appear that when a word
is added to the dictionary, the dictionary is saved out to file (if that's
where it came from) there and then. I wasn't providing a file as the
dictionary - I had constructed a URL and was using that to get the file.
However, this was read only, and the Jazzy code will expressly not write
out changes unless the dictionary came from a file.
This should be documented a bit better, really... Or at least there should
be some feedback to the user to tell them the dictionary couldn't be
saved.
I'm going to work around this by copying the dictionary that comes in my
app's JAR file to the user's home directory once, and then use that.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
One last thing I needed to do to get this working was to set the user
dictionary on the JTextComponentSpellChecker component I used each
time a user clicked the 'spell check' button, to the same dictionary as the
one given to that class in its constructor. Then, it seemed to work. Don't
forget to use one dictionary throughout your application - otherwise you'll
have the overhead of bringing all those new words in each time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The no argument constructor for SpellChecker sets the
userdictionary to a non-file based dictionary. Any
words/dictionaries you add to this SpellChecker, will not be
added to any file.
The other constructors,also use the no argument constructor,
before adding dictionaries. Even if you tell the
SpellChecker to use a file based dictionary in the
constructor, it will not keep track of it.
To get around this, without recompiling SpellChecker, use
the no argument constructor, and call setUserDictionary ()
afterwards.
So, instead of
SpellChecker spellChecker = new SpellChecker (dict);
do
SpellChecker spellChecker = new SpellChecker ();
spellChecker.setUserDictionary (dict);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Could anyone please verify that this is still an issue? If
someone could verify it against Jazzy directly (not JEdit),
etc., that'll at least lessen the workload to resolve this.
Make sure that you're calling setUserDictionary(...) on the
SpellChecker, and that what you pass in is a
SpellDictionaryHashMap, initialized using the (File)
constructor. Assuming the file is accessible (e.g. not JAR'd
up) and writable, it will add the word to the map, and try to
commit it to disk.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=1026922
I too am having this issue. I think it may be something to do with the
dictionary I'm using (i.e. with it being on the disk). I'm using Jazzy to
check the text in one of the components I'm using in a Java application
I'm writing.
Do we have to write back out the dictionary when we're done, or
something? This seems a bit wrong, since the when I add words to the
dictionary, they are not preserved between Jazzy dialog instantiations -
even though I'm using the same dictionary object. So where does Jazzy
store these additional words?
I've taken a look at the source code too, and I'm having difficulty
determining where the add to dictionary code is. I can see there is a
method in the interface class SpellCheckEvent and that the
BasicSpellCheckEvent class implements this method, but I can't follow
what goes on then - it looks like two member variables are set, but I
don't understand where the actual replacement of the words happens.
Logged In: YES
user_id=1026922
OK, so now I've figured out where the word replacement happens. It
occurs in the 'fireAndHandleEvent' method of the SpellChecker class. It
will add the new word to the user dictionary. I assume it is then our
responsibility to save out this user dictionary somewhere when our
application exits if we want to save the additional words. However, this
doesn't explain why the words I add aren't remembered between
instantiations of the 'JTextComponentSpellChecker' class I use... more
probing required.
Logged In: YES
user_id=1026922
Right, I've figured out what's going on. It would appear that when a word
is added to the dictionary, the dictionary is saved out to file (if that's
where it came from) there and then. I wasn't providing a file as the
dictionary - I had constructed a URL and was using that to get the file.
However, this was read only, and the Jazzy code will expressly not write
out changes unless the dictionary came from a file.
This should be documented a bit better, really... Or at least there should
be some feedback to the user to tell them the dictionary couldn't be
saved.
I'm going to work around this by copying the dictionary that comes in my
app's JAR file to the user's home directory once, and then use that.
Logged In: YES
user_id=1026922
One last thing I needed to do to get this working was to set the user
dictionary on the JTextComponentSpellChecker component I used each
time a user clicked the 'spell check' button, to the same dictionary as the
one given to that class in its constructor. Then, it seemed to work. Don't
forget to use one dictionary throughout your application - otherwise you'll
have the overhead of bringing all those new words in each time.
Logged In: NO
The no argument constructor for SpellChecker sets the
userdictionary to a non-file based dictionary. Any
words/dictionaries you add to this SpellChecker, will not be
added to any file.
The other constructors,also use the no argument constructor,
before adding dictionaries. Even if you tell the
SpellChecker to use a file based dictionary in the
constructor, it will not keep track of it.
To get around this, without recompiling SpellChecker, use
the no argument constructor, and call setUserDictionary ()
afterwards.
So, instead of
SpellChecker spellChecker = new SpellChecker (dict);
do
SpellChecker spellChecker = new SpellChecker ();
spellChecker.setUserDictionary (dict);
Logged In: YES
user_id=1212305
Could anyone please verify that this is still an issue? If
someone could verify it against Jazzy directly (not JEdit),
etc., that'll at least lessen the workload to resolve this.
Make sure that you're calling setUserDictionary(...) on the
SpellChecker, and that what you pass in is a
SpellDictionaryHashMap, initialized using the (File)
constructor. Assuming the file is accessible (e.g. not JAR'd
up) and writable, it will add the word to the map, and try to
commit it to disk.