• Post Reply Bookmark Topic Watch Topic
  • New Topic

two jtables with the same defaulttablemodel, but different data in one one column  RSS feed

 
Kris Tine
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi. so i have two jtables with the same table model. both tables have the same data in first 2 columns except for the last one. here i tried doing it by this code:




the table1 should have jcheckbox on the last column, while the table2 has ID numbers on the last column. but the only thing this code do is table1. the last column of table2 will change data into "false". i already asked this to other sites but they said it doesn't make sense. is this not possible at all?
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think this discussion would fit better in our GUIs forum: moving.
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i already asked this to other sites but they said it doesn't make sense


and your question still doesn't make any sense when you post it here. Repeating the same question does not make it clearer just because you post it in a different forum.

You said:

i have two jtables with the same table model

but then you say:

both tables have the same data in first 2 columns except for the last one.

So if they have the same model how can the data in the last column be different? How can an "ID number" turn into "false"?
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is hard to tell from what you wrote what exactly you are trying to ask.

However it is possible to have two JTables share a single table model and not show the same values.

The table model could have four columns, for example, and the first JTable could show columns 0, 1, and 2 (by hiding column 3) and the second JTable could show columns 0, 1, and 3 (by hiding column 2). You can hide columns by calling myJTable.removeColumn(). If the user edits a value in the first two columns of one of the JTables, the change will also be reflected in the other JTable, because they are sharing the model.

Now you could also have a table model with six columns, have the first JTable show columns 0, 1 and 2, and have the second JTable show columns 3, 4, and 5. But in this case I think it would be preferable simply have two separate table models with three columns each.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!