• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Help with AbstractTableModel - Please!!  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've included a sample of the code I'm using - Im using a list(rowList) within a list(dataList) and it repeatedly displays the first item in dataList(ie rowList) for the number of rows that should be in the table.
Any help or advice would be greatly appreciated - thanks.

[Andrew: put code inside [code] blocks]
[ March 04, 2004: Message edited by: Andrew Monkhouse ]
 
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karen,
The first thing that struck me was that you are using a linked list where and ArrayList would be quicker because it allows for random rather than sequential access. I would personally have only one collection instance variable not three, to hold the row data and perhaps an array to hold the cell data (You know what size a row it will be and it is not unreasonable to think the size wont change in the future often), not three as you have in your implementation.
Perhaps something like the following would make the constructor less complex.

I dont know the exact structure of your project data object classes but that was a guess at it.
You would now have a collection of table rows and can pass this directly to the Tablemodel constructor and could use it as follows
new TableModel(account.getRows());
TableModel(Collection c){
rows=c;
}
Object getValueAt(col, row){
rows.get(row)[col]
}
I hope this helps it is the way I did it but there are probably infinate other ( quite possibly better) ways of doing it
[ March 04, 2004: Message edited by: Mark Smyth ]
 
author and jackaroo
Posts: 12195
279
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karen,
Welcome to JavaRanch.
I have edited your post to put the code between [code and [/code] UBB tags. Doing this ensures that indenting is preserved, which makes the code easier to read.
When you are writing your post, there are a number of buttons just below the edit pane, which will insert the tags for you, so you don't have to remember what they are.
If you would like to edit your original post so that you can see what I have done, you can click on the button that is just above your post.
Sorry that I don't have time to look at your code right now.
Regards, Andrew
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just realised I didnt answer your question at all in the previous post, but the reason that the code doesnt work is because rowList is an instance variable.
For the first iteration of the while loop say it adds
Date, Transaction, "Number", "Cr Amount", "Dr Amount
[0]2003/4/56, [1] 2, [2] 123456,[3] null, [4]$5.00
This is added to dataList(0)
At the start of the next iteration you get the next entry.
But you havent cleared the rowList
So you want to add to datalist(1)
[0]2004/4/4, [1] 2, [2] 123423,[3] $10.00, [4]$5.00
But you are actually appending it to the previous entry also and so the list keeps getting bigger for each entry put in.
[0]2003/4/12, [1] 1, [2] 123456,[3] null, [4]$5.00
[5]2004/4/4, [6] 2, [7] 123423,[8] $10.00, [9]$5.00
Now when JTable looks for row data it displays the first 5 elements which are always the same in each row.
Solution is to just make RowList a local variable in the while loop
while(entriesIterator.hasMoreElements()){
List rowList=new List();
// Rest of your code
}
Hope this solves the problem, best of luck with it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!