• 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

JTableCellRenderer for one row

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
The problem is: I need when row is selected then in first cell of this row must appear an icon. When the other row is selected in previous row icon must desapperar but in new selected row it must appear and so on.
How I can do this.

thanks in advance.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want the selected row to display an icon, but unselected rows not to? Easy. Extend javax.swing.table.DefaultTableCellRenderer. In the getTableCellRendeererComponent method, check the isSelected parameter. If it is true, add an icon (DefaultTableCellRenderer extends JLabel so just invoke setIcon()). If it is false, do whatever you want for the unselected rows.
When you create your JTable, use aTable.getColumnModel().getColumn(columnIndex).setCellRenderer() to associate a table column with your new renderer.
You should also either extend javax.swing.DefaultCellEditor to do the same thing DefaultTableCellRenderer does or make the column uneditable through your data model to make the table behave properly when someone clicks on the icon cell.
The Java Tutorial has other instructive examples in How to use Tables.
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks A LOT, it works.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic