wood burning stoves
The moose likes Swing / AWT / SWT and the fly likes JTable (Dynamic increase of rows 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 (Dynamic increase of rows" Watch "JTable (Dynamic increase of rows" New topic

JTable (Dynamic increase of rows

Udaya Bascar
Ranch Hand

Joined: Jun 18, 2002
Posts: 32
hi everyone
Initially the display on the JTable
should have 1 row and 2 columns
If the user presses Enter Key on the 2nd column of the
first Row then a Row should be added.
Now the RowCount should be 2.
If the user presses the enter key on the 2nd column of the 2nd Row then
a row should be added resulting in RowCount 3.
ie On pressing Enter key in 2nd column of JTable a new Row should be added to the
existing Table
give a solution to the above query
ur help is appreciated
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Moving to swing forum.
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
You will have to add a listener for the enter button (ActionListener) and in the actionPerformed method you will have to get a handle on the data model, add a row to that model and then fire a table updated event on the table. That should do it.
Udaya Bascar
Ranch Hand

Joined: Jun 18, 2002
Posts: 32

thanks for ur reply on for my posting of dynamic increase of rows
u made a reply that add a listener
i have added key listener and then proceeding on i dont
know how to use data model and firing events
could u help me out with some code for this
i have been frustrated by this problem for a week
need ur help

Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
for adding a table model listener. And:
for general stuff relating to tables. You might want to get a good book - something like the JFC Swing Tutorial.
Your table has a model even if you don't explicitly assign one. use the tableName.getModel() which returns a TableModel (abstract). It's usually easier to work with if you assign your own table model (DefaultTableModel is a good place to start).
I agree. Here's the link: http://aspose.com/file-tools
subject: JTable (Dynamic increase of rows