Skip to main content

Documentfilter on JFormattedTextField or something like it

2 replies [Last post]
pkg
Offline
Joined: 2003-06-16

It not a big problem setting a documentfilter on a JFormattedTextField, but if you have a formatter on the field its a lot harder.

I have a TextField with a RegexFormatter as a default formatter, the Regexformatter is a subclass of DefaultFormatter. DefaultFormatter has its own documentFilter Class, which i can not use
I could overwrite getDocumentFilter in my RegexFormatter and use my own filter, but then it doesn't work as planned anymore.
What im trying to archive i to block the numeric + (VK_ADD) to make it do something else.
I have tried with getInputMap.put... and i can put a abstractAction on it, but it isn't blocked, its still turn up on the screen. only getInputMap.put.. with a char works, but that will block the other + as well

hope someone can help

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Scott Violet

On Wed, Nov 26, 2003 at 09:50:18AM -0500, swing-feedback@javadesktop.org wrote:
> It not a big problem setting a documentfilter on a
> JFormattedTextField, but if you have a formatter on the field its a
> lot harder.

JFormattedTextField enables pluggable formatting by way of the
AbstractFormatter which uess a DocumentFilter. The expectation is
that if you are using JFormattedTextField you will not directly use a
DocumentFilter, otherwise you may get in the way of the formatting.
If you find you need a DocumentFilter, and AbstractFormatter is to
much for you, than you should use JTextField and set the
DocumentFilter yourself.

> I have a TextField with a RegexFormatter as a default formatter, the
> Regexformatter is a subclass of DefaultFormatter. DefaultFormatter
> has its own documentFilter Class, which i can not use
> I could overwrite getDocumentFilter in my RegexFormatter and use my
> own filter, but then it doesn't work as planned anymore.

As there can be only one DocumentFilter if you provide your own
DocumentFilter you'll need to mimick all that is done in
DocumentFilter provided by DefaultFormatter. A better approach may be
for you to subclass AbstractFormatter directly.

> What im trying to archive i to block the numeric + (VK_ADD) to make
> it do something else. I have tried with getInputMap.put... and i can
> put a abstractAction on it, but it isn't blocked, its still turn up
> on the screen. only getInputMap.put.. with a char works, but that
> will block the other + as well hope someone can help

Could it be that you only blocked the pressed key and not the typed
key?

-Scott

pkg
Offline
Joined: 2003-06-16

Hi
thanks for the answer, all the first i knew. But last part about blocking key typed, is where my problem was (i think).
In my processKeyEvent a was checking on VK_ADD, and of cource key typed wont catch that, so a little of programming and i think its there !!
> On Wed, Nov 26, 2003 at 09:50:18AM -0500,
> swing-feedback@javadesktop.org wrote:
> > It not a big problem setting a documentfilter on a
> > JFormattedTextField, but if you have a formatter on
> the field its a
> > lot harder.
>
> JFormattedTextField enables pluggable formatting by
> way of the
> AbstractFormatter which uess a DocumentFilter. The
> expectation is
> that if you are using JFormattedTextField you will
> not directly use a
> DocumentFilter, otherwise you may get in the way of
> the formatting.
> If you find you need a DocumentFilter, and
> AbstractFormatter is to
> much for you, than you should use JTextField and set
> the
> DocumentFilter yourself.
>
> > I have a TextField with a RegexFormatter as a
> default formatter, the
> > Regexformatter is a subclass of DefaultFormatter.
> DefaultFormatter
> > has its own documentFilter Class, which i can not
> use
> > I could overwrite getDocumentFilter in my
> RegexFormatter and use my
> > own filter, but then it doesn't work as planned
> anymore.
>
> As there can be only one DocumentFilter if you
> provide your own
> DocumentFilter you'll need to mimick all that is done
> in
> DocumentFilter provided by DefaultFormatter. A
> better approach may be
> for you to subclass AbstractFormatter directly.
>
> > What im trying to archive i to block the numeric +
> (VK_ADD) to make
> > it do something else. I have tried with
> getInputMap.put... and i can
> > put a abstractAction on it, but it isn't blocked,
> its still turn up
> > on the screen. only getInputMap.put.. with a char
> works, but that
> > will block the other + as well hope someone can
> help
>
> Could it be that you only blocked the pressed key and
> not the typed
> key?
>
> -Scott