• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable Cell data validation/blank cell problem

 
Yash Sharma
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am fairly new to Swings. I have a JTable that has to do some validations before its data is saved:
(1) Each row of the Table allows values within a set range ex:0.5 to 100
(2) The cell may allow blank (later replaced before save with the lower range value)

All cell data will be Float data. My questions:

(a) Right now I am iterating through JTable cells and checking each row-wise cell to see if they are within range. What is the correct way to do such validations?
(b) JTable by default is not allowing me to leave the cell blank (the focus remains on the cell if I try to leave it blank). How can I allow blank cell entries?
(c) If user enters an invalid data (say a String) in the cell that expects Float value, the text stays in the cell even though I clear the TableModel and repopulate the data. Any idea how to get over this?
[ October 07, 2004: Message edited by: Yash Sharma ]
 
Yash Sharma
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers, I need a helping hand on this.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Yash Sharma
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the code. I think that also reflects the problem I am facing namely: I am not able to leave the cell blank (NumberFormatException : Empty String). I must have some valid float value in any case. How to avoid this?
 
luo ware
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey ,try as following:
check the object value returned by getCellEditorValue() within fuction
stopCellEditing().
Object obj=getCellEditorValue();
if(obj.toString.length()<1){super.stopEditing;return ture;}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic