• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable for Data Entry  RSS feed

 
Shyam Sankar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shawn Kitchen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also write a cell editor to edit the characters as they are typed.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!