Forums Register Login

JTable Cell data validation/blank cell problem

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Ranchers, I need a helping hand on this.
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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;}
There is no "i" in denial. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 10259 times.
Similar Threads
KeyEvent handling in a JTable
JTable
JTable configuration
JTable Trouble
JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:29:09.