• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic jtable

 
Gene Hilpert
Ranch Hand
Posts: 51
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm working on a maintenance screen that has a JTabbedPane that has about 15 tabs. Each tab has a jTable. Each of these jtables contains a simple ID (int), value(String) and a description(String).These values are used in drop down lists in the other parts of my application. So one has statues, address types, etc. As you can imagine there is a lot of very similar code. So I thought of making class(BuildMyjTable) that extends the jTable so I can pass in the class of what I want to display, a list of objects that I what to display, and a listener. So I got to a point where I can build and display the jTable using reflection to get the table headings and values. But my problem is with the listener. I have a class(MyModelListener) that implements TableModelListener that will contain the tableChanged method. Then I use that to extend my listener(MyTableModleListener) that I pass into the buildMyjTable constructor. Everything works but I can't figure out how to call the methods in the MyTableModleListener when the tableChanged method fires in MyModelListener. The methods in MyTableModleListen are where the update,insert, delete to the database is done. I'm trying to clean up the code so I can post an example. Thanks
 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I thought of making class(BuildMyjTable) that extends the jTable


Well, I doubt you should be extending JTable for this. You aren't adding any functionality to the table. The table is still displaying data from the TableModel.

A better approach is to use a generic TableModel. Maybe something like the Bean Table Model.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Rob that you should create your own custom TableModel instead; you can extend DefaultTableModel if you want. The JTable is nothing more than just a graphical representation of the data stored in the TableModel. The ID, value etc should go with the data - not the view.
 
Gene Hilpert
Ranch Hand
Posts: 51
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Then I will redo it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic