• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comunication between two JTables

 
Radek Gajdos
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i have a question more than a problem. I've created a GUI which main functionality is to add name and surname by two JTextFields, than view added content in a JTable and to count number of name occurrence in a second JTable which is triggered whenever the content of the first JTable is chaged. All my code seems to be working, but i wonder if there is more elegant way of populating second JTable. I post my code below with a comment in the most dubious places. Any sugestion are welcome.



Best regards, Radek.
 
Paul Clapham
Sheriff
Posts: 21882
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code looks not too bad to me. (Note: I didn't read it very carefully.)

First: the JTables shouldn't be communicating because they are view components. It's the table models which should be communicating -- and that's exactly what you did. So yes, the TableModelListener is the right way to go.

As for your code which summarizes the names from Table I into a smaller Table II, your approach is to update Table II each time a row is added to Table I. It might be simpler just to rebuild Table II completely each time. My guess is that unless Table I had several tens of thousands of rows you wouldn't even notice the time required to do that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!