aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Using TableCellRenderer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using TableCellRenderer" Watch "Using TableCellRenderer" New topic
Author

Using TableCellRenderer

Paras Ahuja
Ranch Hand

Joined: May 22, 2012
Posts: 62
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

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..


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Paras Ahuja
Ranch Hand

Joined: May 22, 2012
Posts: 62
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

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

Joined: May 22, 2012
Posts: 62
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

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

Joined: May 22, 2012
Posts: 62
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using TableCellRenderer