Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using TableCellRenderer

 
Paras Ahuja
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable (having 4 columns) with selection mode set to SINGLE_SELECTION. I have set the cell renderer for last column only.
Now when i select a row in jtable, only the first 3 columns are selected, the last one is not. Please help me.
Thanks in advance....
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most probably you have ignored the isSelected in your getTableCellRendererComponent(). Can you show is your code?
Swing questions are best suited on the GUI forum. Moving..
 
Paras Ahuja
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think isSelected=true; is doing?
Check out http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender for an example on how to make use of the isSelected argument. Essentially, you need to "select/deselect" your renderer component based on the value you get. In your case the selection could be selecting all the text in the text area.
 
Paras Ahuja
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't understand.
Can you exactly tell me why this is happening and how to resolve it?
Can you provide me a demo code?
Thanks...
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The argument isSelected in the getTableCellRendererComponent indicates if the component is selected or not. In your code you are just re-assigning a value to it. What you need to do is change your renderer selection based on the value which you get.

In pseudo code


*Visual indication is usually achieved by tweaking the background/foreground colors, or calling a setSelected(boolean) on the renderer component


Can you provide me a demo code?

Did you check the link I had provided earlier?
 
Paras Ahuja
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i set no cell renderer to any column, and try to select a row, all the 4 cells of row appear to be selected.
I simply can't think why only the first 3 cells of a row appear to be selected, the last cell is not selected because i set cell renderer to the last column.
No idea why this is happening and how to fix it.
@ Manish: i understand what you are saying but i can't think of a solution.
Please help...
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check how the isSelected is used for combo boxes. http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html#renderer
Conceptually you need to do something for your text area
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic