wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTable Cell data validation/blank cell problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Cell data validation/blank cell problem" Watch "JTable Cell data validation/blank cell problem" New topic
Author

JTable Cell data validation/blank cell problem

Yash Sharma
Ranch Hand

Joined: Jan 30, 2003
Posts: 61
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

Joined: Jan 30, 2003
Posts: 61
Ranchers, I need a helping hand on this.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Yash Sharma
Ranch Hand

Joined: Jan 30, 2003
Posts: 61
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

Joined: Oct 12, 2004
Posts: 2
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;}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable Cell data validation/blank cell problem
 
Similar Threads
JTable configuration
JTable
JTable Trouble
KeyEvent handling in a JTable
JTable