• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generic jtable

 
Ranch Hand
Posts: 51
Hibernate Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Then I will redo it.
reply
    Bookmark Topic Watch Topic
  • New Topic