Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Angel007
Posts: 22
Registered: ‎01-19-2009
Accepted Solution

How to change the size of any Field?

Hi, I'm developing a CLDC Application on JDE 4.7, and I have a problem while I create a custom Field (any field, NullField, VertivalFieldManaher, LabalField, etc). I make an override from the getPreferredWidth() or getPreferredHeight() methods to set the new height and width of my field, but when a print a string to console in the method paint, I see that this method paint is executed in a cycle.

 

This an expmple of code:

 

public class ExpanderField extends VerticalFieldManager { public int getPreferredHeight() { return 200; } public int getPreferredWidth() { return 200; } protected void subpaint(Graphics graphics) { //super.paint(graphics); System.out.println("Paint Method Executed"); } protected void sublayout(int width, int height) { super.sublayout(getPreferredWidth(), getPreferredHeight()); super.setExtent(getPreferredWidth(), getPreferredHeight()); System.out.println("layout executed..."); } }// ExpanderField class

 

In this example, the string "Paint Method Executed" is printed constantly. I don't know why the paint method is executed all the time.

 

Anybody know what's happen?

Please use plain text.
Developer
Angel007
Posts: 22
Registered: ‎01-19-2009

Re: How to change the size of any Field?

I think that I found the answer. In other class of my project I put the sentence setPosition(); within the paint() method of a VerticalFieldManager and this sentence call the paint method again, so this make a cycle, and all the fields controlled for this VerticalFieldManager are painted again when is executed the paint method in the VerticalFieldManager.

 

But I have a question for the RIM Developers...

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/... 

 

Why in the code example above, you're using the sentences setPosition(); and getManager().invalidate(); within Paint() method?, so this sentences call constantly the Paint method and don't stop never, it is not a efficient way to program an application.

Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008

Re: How to change the size of any Field?

Hi,

 

 I did'nt find any setPostion() call in the program :smileywink:.

 

 And they have mentioned why they have used invalidate() just make changes in this program and notice the chnage in the behaviour.

 

You will be able to understand it more clearly.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.