• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rendering a JTable cell that contains a JPanel

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable which contains cells of JPanels. The JPanel consists of a
JLable. How can I render the cell so the label shows up in the column?

Thanks.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the DefaultTableCellRenderer class. It extends JLabel and is designed to make this easy. If you want to use a JPanel with a JLabel in it you can do a similar thing. Make a class that implements TableCellRenderer and and have it either extend JPanel or create a JPanel as a member variable. Add a JLabel to it and configure it inside the getTableCellRendererComponent method. Return the JPanel from this method. You can install your renderer with the setDefaultRenderer method for a given column class or you can use the setCellRenderer on one or more TableColumns accessed from the TableColumnModel.
[ February 28, 2005: Message edited by: Craig Wood ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!