JTable InputVerifier

B

Big Jim

Hi,

I'm using a JFormattedTextField as the editor for a JTable column and have
added an InputVerifier to do validation. Even though the
InputVerifier.verify method returns false it still allows the cell to lose
focus simply returning the cell to the last valid value (the
JFormattedTextField standard behaviour).

Anyone know what's going onthere? (java 1.5)

Cheers, Richard.
 
Z

zero

Hi,

I'm using a JFormattedTextField as the editor for a JTable column and
have added an InputVerifier to do validation. Even though the
InputVerifier.verify method returns false it still allows the cell to
lose focus simply returning the cell to the last valid value (the
JFormattedTextField standard behaviour).

Anyone know what's going onthere? (java 1.5)

Cheers, Richard.

Like you said, that is the standard behaviour.
Create a new TableCellEditor (make your life easier, and use
DefaultCellEditor) that doesn't call stopCellEditing and cancelCellEditing
unless the value is valid.
 
B

Big Jim

Cheers, I'll do that.

just out of interest, is that the usual way to do this or a workaround?
I had thought that attaching an InputVerifier to a component (which I
believe a table cell is) was a perfectly viable way to verfiy input and hold
the focus until a valid input is supplied e.g. I can use this method
successfully on a JTextField or JFormattedTextField as long as it isn't in a
JTable.
 
Z

zero

Cheers, I'll do that.

just out of interest, is that the usual way to do this or a
workaround? I had thought that attaching an InputVerifier to a
component (which I believe a table cell is) was a perfectly viable way
to verfiy input and hold the focus until a valid input is supplied
e.g. I can use this method successfully on a JTextField or
JFormattedTextField as long as it isn't in a JTable.

I've never used a JFormattedTextField, but I've heard they're trouble. So,
I stay away from them. It's easy enough to implement custom listeners that
verify input.
 
B

Big Jim

zero said:
I've never used a JFormattedTextField, but I've heard they're trouble.
So,
I stay away from them. It's easy enough to implement custom listeners
that
verify input.

Implemented the stopCellEditing as you suggested, works great, Cheers again.
 
T

Thomas Hawtin

zero said:
I've never used a JFormattedTextField, but I've heard they're trouble. So,
I stay away from them. It's easy enough to implement custom listeners that
verify input.

Difficult to get right and fiddly. Using a custom Document, or better a
DocumentFilter is better and much easier.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top