• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stuck with a custom TableModel  RSS feed

 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone! I am trying to make a custom table for a DB and i am stuck.

I want only the first column to have a checkbox and others not.

Is there a better way to insert the values instead using the getValueAt ?




This is my code

 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want checkboxes in the first column then the getColumnClass() method for that column should return Boolean.class.
 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul for reply.


If you want checkboxes in the first column then the getColumnClass() method for that column should return Boolean.class.


Sorry not making me clear. I have returned that, with the Value class.

The problem in this case is do i have to insert all the columns independently from the DB in the getValueAt(int row, int col) overrided method?


I need a way to insert all the data from DB in one move, all the columns once, like i am using to insert the values in the first column from the DataModel constructor

 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out. I modified the array list to



and added the values from DB to the table. In the getColumnClass method just return Value.class only for the first column.

Now i have problems with sorting...



doesn`t work now
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at our FAQ entry ItDoesntWorkIsUseless, and then post some more information about your question.
 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to say that when i want to sort the values from values

with the method sort from java.util.Collections class

it gives me an error:
Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (List<JTableTest.Value[]>). The inferred type JTableTest.Value[] is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>
This problem is when i modified the structure of the list:
from

to


Like i wrote up in the code the class Value implements the interface Comparable

and i override the method


 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because your Value class implements Comparable, it doesn't follow that Value[] implements Comparable. Which is what the error message is complaining about, although it does it in obscure jargon. And there's no way (that I know of) in Java to declare that some array type implements Comparable.

However what you can do is to use the version of Collections.sort() which accepts a Comparator as its second parameter. That Comparator would have to be designed to compare two Value[] objects.

Or alternatively you could have an object (of a class which implements Comparable) for each row of the table, instead of having an array. This object would contain whatever is in that array. However that would require you to rewrite your table model to accept that change.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!