Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: JTable display

 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to ask, if I have a Tabel Model with, say 8 columns. Can I only display 7 of them in the JTable?
If so, how can I achieve this?
Thanks.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need this becos, in my implementation, I use recNo as primary key.
Even I dont use it, my APIs (given by SUN) all required the input of recNo.
Thus, I guess the records should include this.
But then, I dont think it is a good idea for displaying the recNo in the GUI, becos recNo is not in sequence (if some of them are marked deleted).
So, at the beginning, I create a RecordModel, which defines only 7 fields.
But in fact, when I added a record, it contains 8 fields.
So, the last field (recNo) is not recongized by the JTable.
When I click one row in the JTable, I get the index, refer it to the RecordModel, and then get the value from the "hidden" field.
However, I think it may not be so good becos I should indeed get the "recNo" from the View, NOT the MODEL.
Any suggestions?
Thanks a lot.
 
Paul Tongyoo
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nicholas Cheung:
I would like to ask, if I have a Tabel Model with, say 8 columns. Can I only display 7 of them in the JTable?

Hi Nicholas--
I believe when you create a TableModel by extending javax.swing.table.AbstractTableModel you can override the getColumnCount(int col) function and returning 7, and disregarding all "column 8" values when overridding your getValueAt(int rowIndex, int colIndex) function.

Of course, the above code assumes that your collection is a set of String[] objects. But you'll be overriding these two functions just the same to get the display you want.
HTH
Regards,
Paul
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic