It's not documented as such but I suspect that 0..n-1 was the intention. Looking at the source of JTable the method createDefaultColumnsFromModel relies on this being so.
Dave Wathen Canzonet Limited Phone: +44 (0)20 8660 5171 Mobile: +44 (0)7968 167934 Fax: +44 (0)870 051 7664 http://www.canzonet.com mailto:[EMAIL PROTECTED] -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Ralph Kar Sent: 11 September 2002 08:52 To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Problems with row filtering in JTable Hi Evan, I am afraid, I have to tell you that the model index of the columns does not necessarly have to be from 0..n-1. The view index of the columns is 0..n-1, but the model index can be anything. For example, we use the model index to reference field ids that represent the data displayed in the column. The field id can be any positive integer. The implementation of the DefaultTableModel uses 0..n-1 as column index, but it does not have to be that way. I am also not aware that the specification of the TableModel interface requires the index to be that way. I guess I have to ask Philip about it. Ralph ----------------------------------------------------- Ralph Kar | Software Developer | mailto:[EMAIL PROTECTED] RTS Realtime Systems AG | http://www.rtsgroup.net ----------------------------------------------------- On Tue, 10 Sep 2002, [EMAIL PROTECTED] wrote: > Ralph Kar wrote: > > Hi all, > [...] > > The problem arises when I want to > > implement isRowVisible() (which itself needs to be called by > > TableModel.getRowCount()). This method needs to go over all columns that > > have filters attached to them, get their cell values and apply the filter. > > This means I need to call TableModel.getValueAt() from that method. > > TableModel.getValueAt() requires the columnIndex as parameter. I am unable > > to determine this parameter. TableModel.getColumnCount() only returns the > > number of columns but not the actual indices. Those do not necessarily be > > sequential from 0..n. > > Ralph, > > If a TableModel has a columnCount of n, the indices are always 0..n-1. > > The headings displayed in the table may be something totally different. That > information is in the columnIdentifiers in the TableColumnModel. > > Also, the JTable itself (the view) keeps a separate set of indices because the > user is allowed to move the columns around. It provides two methods for > converting back and forth between view indices and model indices: > > public int convertColumnIndexToModel(int viewColumnIndex) > - Maps the index of the column in the view at viewColumnIndex to the index of > the column in the table model. > public int convertColumnIndexToView(int modelColumnIndex) > - Maps the index of the column in the table model at modelColumnIndex to the > index of the column in the view. > > In the common case, the view indices and model indices are the same. > > Evan McLain > junquemale -at- yahoo.com > > > > _______________________________________________ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing _______________________________________________ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
