This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

modifying default renderer for Boolean class  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to modify the default renderer for Boolean class to disable certain JCheckBox cells in a table.
I overwrote the method getCellRenderer as follows:
public TableCellRenderer getCellRenderer(int row, int col) {
if (col == 0) return this.getDefaultRenderer(String.class);

if (!this.getModel().isCellEditable(row, col)) {
TableCellRenderer renderer = this.getDefaultRenderer(Boolean.class);
if (renderer instanceof JCheckBox) {
JCheckBox box = (JCheckBox)renderer;
box.setEnabled(false);
box.setBorderPaintedFlat(true);
//box.setForeground(Color.LIGHT_GRAY);
//box.setBackground(Color.BLUE);
}
return renderer;
}
return this.getDefaultRenderer(Boolean.class);
}
I would expect this to render all uneditable cells as disabled JCheckBoxes, but it didn't.
Any ideas what I might be doing wrong?
Thanks.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
you can try overriding the belo method.
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column);
Hope this w'd help u.
Tamizh
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!