Adding identifier to table model...

Hi,

I've aJTable which uses theDefaultTableModel class as its table model.

I'm using aVector to add rows to theDefaultTableModel...

When selecting a row of the table I'd like to pass an identifier (primary key which comes from the db) but I'm not quite sure how to achieve this... the vector which is added to the table model just contains values which are displayed in the table so where do I add my identifier (the identifier should not be displayed in the view).

Is there a way to add an identifier to a table model, perhaps something like hidden parameters in HTML?

Thanks in advance

- Stephan

[676 byte] By [Jacklera] at [2007-11-27 11:02:25]
# 1

You can store the identifier in the table that same as any other piece of data.

Then you simply remove the TableColumn represented by the identifier from the TableColumnModel and it won't be painted in the table.

camickra at 2007-7-29 12:43:12 > top of Java-index,Desktop,Core GUI APIs...
# 2

> You can store the identifier in the table that same

> as any other piece of data.

>

> Then you simply remove the TableColumn represented by

> the identifier from the TableColumnModel and it won't

> be painted in the table.

Hi camickr!

if you told the OP to remove that column just like this:

TableColumn col = table.getColumnModel().getColumn(0);

table.getColumnModel().removeColumn(col);

how to retrieve that data from that column?

Yannixa at 2007-7-29 12:43:12 > top of Java-index,Desktop,Core GUI APIs...
# 3

As I mentioned the data in the TableModel is not affected. So instead of using:

table.getValueAt(...);

you use

table.getModel.getValueAt(...);

camickra at 2007-7-29 12:43:12 > top of Java-index,Desktop,Core GUI APIs...
# 4

>table.getModel.getValueAt(...);

i didn't know that either.

man your good.

Thanks for the additional knowledge. :)

Yannixa at 2007-7-29 12:43:12 > top of Java-index,Desktop,Core GUI APIs...
# 5

Yes, putting the identifier to the model and removing the column so it won't be painted is the trick... thanks a lot.

- Stephan

Jacklera at 2007-7-29 12:43:12 > top of Java-index,Desktop,Core GUI APIs...