Forums Register Login

Question about JTextComponent Heirarchy

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1129 times.
Similar Threads
Textarea Text Alignment?
JTextComponent: Making certain text within the component as Bold
Font in JTextComponent
How do I bold the text in a text area?
Alignment for centering text in JTextPane does not work
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:00:46.