• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using TableCellRenderer

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic