Results 1 to 4 of 4
Thread: Adding Rows to a JTable
- 05-04-2011, 12:51 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 22
- Rep Power
- 0
Adding Rows to a JTable
{SOLVED}
Hey everyone,
I am trying to add a row (or more) to a JTable on a button push, with the following method (explanation below):
Java Code:
The jTable and DefaultTableModel were created in NetBeans Swing pallette with some customisation to allow me to access toe DefaultModelTable:
Java Code:
The table starts out with no rows, although the column headers are visible. When the button is pushed, the code iterates through a LinkedList<Item> (Item is a superclass to Power) stored in the static Basket class, and takes data from each item to add it to the column.
I have confirmed that there are items are correctly stored in the basket.
The data is converted to Strings in one way or another and should be added to the table as an array using the tableModel1.addRow() method.
My trace statements all fire, so the code definitely reaches this line when the code is ran, but the row is not added to the table for some reason, because when I print out the row count it remains zero.
I am not getting any exceptions or error messages.
I am also aware that fireTableDataChanged() isn't necessary when using addRow(), it didn't help with or without.
Help would be greatly appreciated!Last edited by mlad; 05-04-2011 at 09:45 PM. Reason: code
-
I wonder if you have more than one DefaultTableModel object, one that is used by the displayed JTable and that has no rows, and another distinct DefaultTableModel object that is not displayed but that gets rows added to it. We will need to see more code I think to solve this, and the best code to create and post here (if possible) is an SSCCE.
- 05-04-2011, 02:07 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 22
- Rep Power
- 0
You must have excellent debugging intuition! I was actually using 3 JTables and 3 DefaultDataModels, unfortunately named jTable1, 2 and 3 and tableModel1, 2 and 3; I took two out to push my post towards SSCCE.
I was testing adding rows on jTable2 only, but had assigned it tableModel3. Spotted this after reading your suggestion. It is working now, thank you!
-
I've tripped over this problem myself -- we all have. Glad you've got it fixed.
Similar Threads
-
Jtable rows
By riddhishah28 in forum AWT / SwingReplies: 3Last Post: 02-18-2011, 06:24 AM -
Remove Jtable rows
By anilkumar_vist in forum Advanced JavaReplies: 2Last Post: 09-17-2010, 08:03 AM -
JTable insertRows() just adding blank rows
By Jacob_ in forum AWT / SwingReplies: 4Last Post: 10-10-2009, 03:56 AM -
Highlight rows of a jtable
By simmi in forum AWT / SwingReplies: 5Last Post: 08-20-2009, 01:13 PM -
display rows in jtable
By osval in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks