aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Subclassing JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Subclassing JTable" Watch "Subclassing JTable" New topic
Author

Subclassing JTable

henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

Moving to our Swing/AWT/JFace/SWT forum.


[Jess in Action][AskingGoodQuestions]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Inside your constructor you would write

Elsehere you would write


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
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
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
Then you're doing it wrong:
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
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..
 
 
subject: Subclassing JTable