How to make a table field to accept only numbers. If it is any other (key), it should not display it in that field. IS that possible? If so please let me know.
Asked
Active
Viewed 1,994 times
1 Answers
4
I must admit I have not tested this, but the default JTable
has an inner class NumberEditor
(javax.swing.JTable.NumberEditor). So I assume that when your TableModel
correctly indicates the column class is a number extension, the default editor will be one that only accepts numbers
If the default editor is not what you are looking for, you can write your own editor, for example by using a JFormattedTextField
as editor. See the Swing table tutorial for more information. This tutorial contains a section about a custom editor which should get you started if you want to write your own editor.

Robin
- 36,233
- 5
- 47
- 99
-
@trashgod it seems you have sample code for almost every problem that is posted here. I am surprised you even remember all your snippets – Robin Apr 23 '12 at 12:27
-
1Ixnay; I'm using SO for off-site backup, but no one must know! :-) – trashgod Apr 23 '12 at 21:03