Forums Register Login

JTable for Data Entry

+Pie Number of slices to send: Send
Hi,
I am new to client side Java.
So this question may sound silly.
I want to use a JTable for DataEntry purpose.
Initially I want to display 15 blank lines and add more lines as needed.
Does this mean I have to create an ArrayList or Vector of initial size 15 with all the values set to "".
Also I want to do some field level validation in the JTable. Is it possible to validate the values entered in a particular cell on pressing the tab key?
Thanks
Best Wishes
Shyam
+Pie Number of slices to send: Send
Yes, you can create 15 blank rows by creating 15 blank line items and then display them like they're actual data. And yes, you can verify the data as it's entered. One way to do this is with TableModel's setValueAt method. For example if you want to make sure that an integer is entered in at column 3 you could write something like this:
public void setValueAt(Object value, int nRow, int nCol) {
if(nCol == 3) {
try {
int qty = Integer.parseInt((String)value);
fireTableCellUpdated(nRow, nCol);
break;
}
catch(NumberFormatException nfex) {
JOptionPane.showMessageDialog(Constants.CLIENT_APP_FRAME, "Please enter a valid quantity.", "Invalid Number",JOptionPane.INFORMATION_MESSAGE);
}
Hope that helps
+Pie Number of slices to send: Send
You could also write a cell editor to edit the characters as they are typed.
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1327 times.
Similar Threads
JTable
jtable
Generic jtable
JTable
JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:27:46.