This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jcomponent in JTable cells  RSS feed

 
Zakaria Haque
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not very familiar with swing. I am trying to use some JComponent in a table. The problem is, though I see the JComponents in the cells, they dont receive any event. I set a custom TableCellRenderer for JComponent type. Here is the code,
table.setDefaultRenderer(javax.swing.JComponent.class,
new TableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
return (JComponent) table.getValueAt(row, column);
}
});
setMiddleComponent(table);
}
Also, I have those JComponents in the table model, is this design ok for mvc?
I will be very glad if you have the answer, or you can point me to any resource that duscusses this issue.
Thanks.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you explain what you are trying to do? Renderers and events don't have anything to do with each other. The renderer is for display editors are for what happens in JTables. JComponent doesn't really narrow down what you are trying to accomplish.
Here is a link to a site that puts various JComponents in JTables.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!