• Post Reply Bookmark Topic Watch Topic
  • New Topic

jtable column with defaultcelleditor(jcheckbox) does not get highlighted when selected  RSS feed

 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i have a running jtable with a column that has jcheckbox in it and i assigned a defaultcelleditor for that

my problem is that i cant figure out why when i select a row in the jtable, the column with the jcheckbox does not get highlighted as well.
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like an issue with the renderer, not with the editor.

If you use JTable's built-in checkbox renderers/editors then everything should work fine. (Everything can work fine if you use your own, too, but it might be more work.)
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i managed to make it work. but i had to use defaultcelleditor as the editor of the checkboxcolumn and not tablecelleditor. that way, in the renderer, i could call the component.setBackBround(table.getSelectionBackground());

 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mark chester goking wrote:yeah i managed to make it work. but i had to use defaultcelleditor as the editor of the checkboxcolumn and not tablecelleditor. that way, in the renderer, i could call the component.setBackBround(table.getSelectionBackground());


TableCellEditor is just an interface. You are free to call component.setBackground() in your implementation, and in fact should do so. It's usually easier to use DefaultCellEditor anyway, though.

Actually, it's even easier to use JTable's default checkbox renderers/editors, but for some reason newcomers are often reluctant to use them. I'm not sure why.
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had to use celleditors because i wanted my checkboxes to be disabled at some point. if i use just a renderer, when i click the cell, the checkbox appears for a short stint. at least using a celleditor, i was able to disable those that i wanted via the iscelleditable method to ignore if cells are clicked.

im tackling a different problem now. hiding some leaf nodes in a tree he he he

im stuck with a little prob. maybe you can give me some ideas

http://www.coderanch.com/t/466149/Swing-AWT-SWT-JFace/java/filtering-N-number-leaf-nodes

thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!