Results 1 to 3 of 3
Thread: Extends JLabel
- 10-24-2012, 11:17 AM #1
Member
- Join Date
- Aug 2010
- Location
- Leuven, Belgium
- Posts
- 79
- Rep Power
- 0
Extends JLabel
Hi,
I want to use my own labels in the programm.
So i have extend JLabel to put my own extentsions in it.
But when i want to use the ".setHorizontalTextPosition" on such a Label it does not work.Java Code:public class Label extends JLabel { public Label(String s) { super(s); } }
I get the following error message
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.awt.Label.setHorizontalTextPositionWhy is that ?Java Code:Label label = new Label("text"); label.setHorizontalTextPosition(0);
The "".setHorizontalTextPosition" is public in JLabel thus an extends of JLabel must have acces to it.
instead i have to make first an implementation of "Label"
Then this is working.Java Code:public class LabelImpl extends Label { public LabelImpl(String s) { super(s); } }
What is the reason for that ?Java Code:LabelImpl label = new LabelImpl("text") ; label.setHorizontalTextPosition(0);
Kind regards
Dipke
- 10-24-2012, 01:15 PM #2
Member
- Join Date
- Aug 2010
- Location
- Leuven, Belgium
- Posts
- 79
- Rep Power
- 0
Re: Extends JLabel SOLVED
Problem solved.
I have imported the awt.label instead of my label object.
Thats why it was not working
- 10-24-2012, 01:50 PM #3
Re: Extends JLabel
Always a bad idea to name your custom classes the same as a JDK class (and especially so when the name of a class in the java.lang package is duplicated).
That said, are you sure you want to use inheritance? It's usually better to write a method (or a static method in a utility class) that sets the desired attributes of an unextended JLabel.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
problem with two extends of Inheritance
By MaceMan in forum New To JavaReplies: 29Last Post: 04-14-2011, 04:06 PM -
Initialize Vs extends
By N00Bie in forum New To JavaReplies: 1Last Post: 03-22-2011, 02:58 PM -
Adding a JLabel to a JPanel - jlabel not showing
By Bongeh in forum New To JavaReplies: 17Last Post: 04-06-2010, 11:02 PM -
extends question
By mac in forum New To JavaReplies: 8Last Post: 04-03-2010, 02:29 AM -
My icon extends my JButton
By hitmen in forum AWT / SwingReplies: 5Last Post: 03-06-2009, 07:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks