| Author |
Generic jtable
|
Gene Hilpert
Ranch Hand
Joined: May 22, 2002
Posts: 49
|
|
|
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
Joined: Jun 13, 2009
Posts: 1808
|
|
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
Joined: Oct 27, 2005
Posts: 19232
|
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Gene Hilpert
Ranch Hand
Joined: May 22, 2002
Posts: 49
|
|
|
Thanks Then I will redo it.
|
 |
 |
|
|
subject: Generic jtable
|
|
|