File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Question about JTextComponent Heirarchy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question about JTextComponent Heirarchy" Watch "Question about JTextComponent Heirarchy" New topic
Author

Question about JTextComponent Heirarchy

Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
This question is based on an example of JEditorPane and JTextPane, but probably the issues are general to the class heirarchy.

OK it is my understanding that whan class B is a subclass of class A in the java class heirarchy, that means it extends that class, it adds to the functionality. One of the things that means is that from a constructor of class B you can use the super keyword to invoke a constructor of class A, thereby extending the functionality of that class A constructor.

But in the Java Tutorial I came across a comment that casts doubt upon the above. on the following page http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html, we have the following paragraph.

An editor pane or a text pane can easily be loaded with text from a URL using the setPage method. The JEditorPane class also provides constructors that let you initialize an editor pane from a URL. The JTextPane class has no such constructors.

This puzzles me. In light of the fact that extending a class is supposed to expand its functionality, what is the significance of this comment which seems to suggest that in some ways a subclass has less functionality?

This seems too obvious, so no doubt it is late and I am tired and missing something. I guess not all constructors in a higher class can be invoked by super?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

This would lead one to deduce, that the constructors are not inherited by the subclass. What do you think?

More detailed and official information here


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Maneesh Godbole wrote:This would lead one to deduce, that the constructors are not inherited by the subclass. What do you think?

More detailed and official information here


Indeed, but in the very same sentence on the page you linked, it says "... but the constructor of the superclass can be invoked from the subclass."

Which still leaves the question. Why would they say in the example I described that the superclass has such and such a constructor but the subclass doesn't, when ostensibly if the superclass has the constructor, the subclass doesn't need it, all the subclass should need to do is invoke said constructor using super.

Again, I guess super doesn't apply to every constructor?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

I think the idea is to give you ready made constructors which you would typically use. In case you require additional functionality, you got two options. 1) Provide your own constructor and invoke the appropriate super constructor. 2) Use the required methods from the super class.

I don't think I have managed to explain things clearly.
Since this is not restricted only to Swing, I will move this to the appropriate forum. Someone else can provide a better explanation.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
OK, thanks anyways. I'm beginning to see the error of my thinking. How does one invoke a JEditorPane constructor from a JTextPane class anyways. If I have a super keyword that is invoking a JEditorPane constructor, then I must be in a 'custom' subclass that extends JEditorPane, and JTextPane really doesn't enter into the picture.

Yep, it must be the tiredness.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about JTextComponent Heirarchy
 
Similar Threads
doubt over final overriding
Doubt regarding Constructor
Inheritance
Constructor doubt
doubt