I wanted to subclass JTable to use in my application. The Table works correctly, but I want to add Event functionality. I tried to add the line this.addTableModelListener(); to this class but it gave a compiler erro. I tried to add the same line to my JFrame clas used to display the instantiated JTable and it did not work.
Ernest Friedman-Hill
author and iconoclast
Marshal
That being said, your design looks bad. First, do you *really* need to subclass JTable? What JTable method are you overriding? Second, this sort of typing is bad:
because one can do the following with it:
Did you really intend to have one table listen to another? I suspect you wanted to define a table that needed, solely as an implementation detail, to define a TableModelListener. In that case, I would define a seperate class implementing TableModelListener, or if you really need it to access implementation details of Table, to do this:
[ November 02, 2005: Message edited by: Jeff Albrechtsen ]
There is no emoticon for what I am feeling!
henri henri
Ranch Hand
Joined: Oct 03, 2005
Posts: 115
posted
0
I made a subclass of JTable to take some of the design code out of my JInternalFrame class which displays the Table. Thanks for all of your suggestions.
henri henri
Ranch Hand
Joined: Oct 03, 2005
Posts: 115
posted
0
I tried your suggestion in my code, and none of it works as you suggested.
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Then you're doing it wrong:
henri henri
Ranch Hand
Joined: Oct 03, 2005
Posts: 115
posted
0
Thanks, I will give it a try. I would simply like to be able to re-edit the JavaBean values in my JTable and have those values be transmitted back to the JavaBean via the set methods i have designed in my FilmBean class.
Thanks for your advice on subclassing. it seems that it is not a good idea to do it if one can avoid it.
I have about 60 lines of code in my JTable subclass. it seemed to make sense to keep it in a separate class and instantiate it in the class that will display it like so Table table = new Table(model); All of the configuration is taken care of in the subclass. Apparently alot of java people are dead set against this approach. I don't have enough experience to understand it or grasp why..