• 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

JTable and Custom TableCellRenderer - selection problem

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey everyone, I am using a custom TableCellRenderer to render a column in a JTable. This works great BUT when I select a column in the table, the column that is using the renderer is not highlighted. My custom renderer is pasted below. Does anyone know how I can highlight the JLabel if isSelected is true? Thanks.
class MyTableCellRenderer extends JLabel implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {
setText(value.toString());
// more stuff here
return this;
}
}
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to use the isSelected boolean the the method signiture and set the background you self...
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you are using j2se 1.4 or might ever going to use it, you should extend the DefaultTableCellRenderer not just implement the interface. this makes a big performance difference. see the API of DefaultTableCellRenderer and the source code (1.4!) for more information. moreover, inheritance might spare you some code concerning the selection problem.
cheers
reply
    Bookmark Topic Watch Topic
  • New Topic