aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Auto row generation in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Auto row generation in JTable" Watch "Auto row generation in JTable" New topic
Author

Auto row generation in JTable

Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,
Is it possible to have a JTable for data entry?
The idea is that this table shows only one row at start and whenever the user press tab in the last column of the table, a new row is added so that he may make new entries. This means to somehow pick up the tab key in the last column (what class/listener to use?) and genetarte a new row add it to table and update the table, being careful that previous entries are not lost...(quite a job!)
The second solution may be to estimate the maximum required rows for entries and display them right from the start. But the problem in this solution is how to know that, say, the first 20 rows have data and not the remaining 30 ones?
Any ideas plus code plz,
Thanx in Advance

Maki Jav


Help gets you when you need it!
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
you can add new row with JTableModel


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Would you be elaborate please?
Thanx
Maki Jav
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
hello,
it to simple first creat defaulttablemode then add table in defaulttablemodel..
DefaultTableModel df = new DefaultTableModel();
JTable tb=new JTable(df);
then u can add new row as
df.addRow(new String [] {"","","","",""});
that all...
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
That easy?!Gee thanks!
Now the second part...
How will I detect that the tab key was typed in the last column. I am able to get the key typed in any column of the JTable but not a specific column. Is there any solution?
Thanx,
Maki Jav
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Auto row generation in JTable