1

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
vicky
  • 1,046
  • 2
  • 12
  • 25

1 Answers1

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
  • 1
    Ixnay; I'm using SO for off-site backup, but no one must know! :-) – trashgod Apr 23 '12 at 21:03