By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,468 Members | 1,865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,468 IT Pros & Developers. It's quick & easy.

Casting Font object into Element--- Need Help!!

P: 18
Hi all

I really need a solution for the following::
-------------------------------------------------------------------------------------
Say i have a font object called 'myFont' as shown below;

Font myFont= domainAxis.getTickLabelFont();

I need to cast "myFont" object into a "Element" object as i shown below

Element newFont = (Element)myFont;

but this casting doesn't work; it is giving a Casting Exception; How can i cast a Font object in to an Element object?? Because i need to change attributes on that Element object and re-converted iy back to a Font object as below.
--------------------------------------------------------------------------------------
newFont.setAttribute("kerning", "no");
newFont.setAttribute("family","SansSerif");
newFont.setAttribute("name","SansSerif");
newFont.setAttribute("style","plain");
newFont.setAttribute("size","10");

domainAxis.setsetTickLabelFont((Font)newFont);

-------------------------------------------------------------------------------------

How to do the "Font " to "Element" Casting
Regards
Madumm
Jan 19 '07 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
Hi all

I really need a solution for the following::
-------------------------------------------------------------------------------------
Say i have a font object called 'myFont' as shown below;

Font myFont= domainAxis.getTickLabelFont();

I need to cast "myFont" object into a "Element" object as i shown below

Element newFont = (Element)myFont;

but this casting doesn't work; it is giving a Casting Exception; How can i cast a Font object in to an Element object?? Because i need to change attributes on that Element object and re-converted iy back to a Font object as below.
--------------------------------------------------------------------------------------
newFont.setAttribute("kerning", "no");
newFont.setAttribute("family","SansSerif");
newFont.setAttribute("name","SansSerif");
newFont.setAttribute("style","plain");
newFont.setAttribute("size","10");

domainAxis.setsetTickLabelFont((Font)newFont);

-------------------------------------------------------------------------------------

How to do the "Font " to "Element" Casting
Regards
Madumm
Please do not double post. For a cast to work, the objects must be convertable.
i.e
Type2 b = new Type2();
Type1 a = (Type1) b;
For this to work, then class Type1 must extend Type2 directly or indirectly otherwise you get a class cast exception at runtime.
Jan 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.