removing mouse selection support from JFormattedTextField
Hi.
First a little background info:
I have created a class DateField that extends JFormattedTextField. This class will eventually act as the Editor component in an editable JComboBox.
Upon creation of an instance, a pattern should be passed as a String argument to the constructor. E.g. 搚yyy-MM-dd? This pattern is presented as default to the user using super.setText(pattern); The caret color is set to the same as the background, hence it will become invisible. The first char in the pattern is selected using setSelectionStart(0) and setSelectionEnd(1), se screenshot, http://www.jorgenpersson.se/DateField_1.jpg.
The arrow keys can be used to move the selection right or left. When the user types a check is made to see if it is a valid char. In this case only a digit is valid. If delete or back space is pressed the selected char is replaced by the char at the equivalent position in the pattern string. So far all good.
Now, here抯 my problem:
Using the mouse you can select a range of characters. I want to disable this functionality.
I figured the start of the selection has to be triggered by MouseEvent. I therefore added a MouseListener and consumed the MouseEvent in the mousePressed method, but without success. I then, for testing purposes, tried to remove all existing MouseListener抯 from the parent. This didn抰 help either. The solution I have now is not something I like. In mouseReleased(? I simply select the character at the position of the caret.
Can anybody guide me to where I can turn mouse selection of. Which class is responsible?
[1613 byte] By [
STTPokera] at [2007-11-26 22:18:36]

> Using the mouse you can select a range of characters.
> I want to disable this functionality.
Well, you can do that with the keyboard as well. Are you going to ask how to disable that as well? I suggest you go back a couple of steps and ask yourself why you need to micro-manage the user who is trying to enter a date. You might find it easier to just provide a date selection control where the user can just click on the date from a calendar display.
> You might find it easier to just provide a date selection control where the user can just click on the date from a calendar display.
That's true, but reinventing the wheel isn't always bad. As in my case, I love programming and when reiventing the wheel I learn something, which makes me a better programmer.
> That's true, but reinventing the wheel isn't always
> bad. As in my case, I love programming and when
> reiventing the wheel I learn something, which makes
> me a better programmer.
Can't argue with that. However in posting here you have jumped to the quick but wrong conclusion too. There is a Swing forum further down the page. Easy Swing questions get answered in this form, hard ones either don't get answered or get bad answers. It's better to ask questions like this one where the experts hang out.
> Can't argue with that. However in posting here you
> have jumped to the quick but wrong conclusion too.
> There is a Swing forum further down the page. Easy
> Swing questions get answered in this form, hard ones
> either don't get answered or get bad answers. It's
> better to ask questions like this one where the
> experts hang out.
Before posting my question here I scrolled the list but obviously I missed that one, sorry about that. I'll repost my question there.
If it's easy or not is a question of who your asking and if the problem was formulated / understood correctly. I know how to remove the effect of a multichar selection, but not how to disable the possibility to make a multichar selection.
This will be my last post in this thread. Swing forum, here I come :)