Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading JTables with javabeans

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone ever heard of a way of building a JTable using javabeans where the javabean not only the data but the way the data is displayed?

I'm looking for a generic table building model.

Thanks.
 
David Mace
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by the bean not only contains the data, but the way it is to be displayed, but I'll take a guess at your meaning. If you mean that, for instance, you have a boolean value and instead of a JLabel simply stating either true/false versus having a checkbox, then here's the solution.

You'll first want to implement a custom table model....start by extending AbstractTableModel. In order to set a column to display using something other than the default JLabel, you'll need to create a custom renderer for that column. I'll leave you with that info and you should be able to google the remaining piece of the puzzle for your answer. It's really simple to do.

David
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic