I have a JTable that has two columns (editable JTable). When a user types something in the second column, my requirement is as follows:
user can only typewrite a number and comma
when user type wrong character, it will beep
(Toolkit.getDefaultToolkit().beep();
)
How do I go about achieving this? (if it jtextfield it need document filter or plain document etc, if it JTable, then how?)
Implement a
TableCellEditor
that is capable of returning a text component (JTextField
) that has aDocumentFilter
attached to it capable of filtering the incoming text as you require.You might like to take a look at
UPDATED with example
Read the tutorials, ask questions specific to the problem you're having. It's important that you understand why things are done in a certain way rather then simply copying and pasting some one else code, otherwise you won't know when you're copying bad ideas ;)