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
Posts: 43
Registered: ‎08-26-2010
My Device: Not Specified
Accepted Solution

Rotation and repaint fields

[ Edited ]

Hi, 

 

I am current having problems with a screen i am developing,  I current have my own implementantion of a textField which basically extends textField but excepts a height and width figures and draws accordingly.  The problem is i have overriden the sublayout method to set these figures so when the screen is rotated the  fields with expand.  My problem is that it appears to be repainting based on the previous set of values. 

 

Am i missing something or am i on the wrong track?

 

Cheers

 

ps i meant to say it works ok on a simulator but seems to be behaving as described above on the deveice

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Rotation and repaint fields

You must be saving something on the first sublayout and not updating it properly on the subsequent ones. Something like

 

private myHeight = Integer.MIN_VALUE;

...

protected void sublayout(int w, int h) {
  myHeight = Math.max(myHeight, h);
  ...
}

protected void paint(Graphics g) {
  // paint something using myHeight
  ...
}

In this example, once myHeight goes to the maximum value it will never go down - which is a bug.  Look for such logical bugs first....

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 43
Registered: ‎08-26-2010
My Device: Not Specified

Re: Rotation and repaint fields

[ Edited ]

ok i will have a look at that but basically in the sublayout i am doing the following for each filed of mine that is on screen,

 

 

userText.setWidth( (Display.getWidth()-10));

 

So basically i am setting it so that it wont take up the full screen but stop just before the edge of the screen.

 

Isnt that correct?

 

 I also can keep rotating the device from port to land and back again and the settings do change but its like its always one "rotation" behind

Developer
Posts: 43
Registered: ‎08-26-2010
My Device: Not Specified

Re: Rotation and repaint fields

Sorry no joy dont see any mistakes but there must be something im missing

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Rotation and repaint fields

If I were to make a wild guess, I would say that during sublayout() you are bound to get stale values from any getWidth() / getHeight() aside from the Fields you are sure to have laid out already (as in layoutChild(child, w, h) with subsequent child.getWidth()).  This is definitely true for Screens, Managers and Fields - my guess is that it also applies to Display.

 

Stop using Display.getWidth() and use the width passed down to you in your sublayout() call.  That value is guaranteed to be correct.

 

Another possibility would be to override your Screen's sublayout() like this:

 

protected void sublayout(int maxWidth, int maxHeight) {
  myApp.screenWidth = maxWidth;
  myApp.screenHeight = maxHeight;
  super.sublayout(maxWidth, maxHeight);
}

 where screenWidth and screenHeight are public static int members in your application (or your main screen).  You could then use those screenWidth / screenHeight anywhere you need them instead of Display.getWidth() / Display.getHeight() (and eliminate a signature-requiring call in the process). :smileywink:

 

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 43
Registered: ‎08-26-2010
My Device: Not Specified

Re: Rotation and repaint fields

Thanks for the help it pointed me in the right direction it appears i was calling super.subLayout(h, w) to early in my overriden method.  For anyone who might have the same problem in future: 

protected void sublayout(int width, int height) {

 

 

    userText.setWidth( );

 

    super.sublayout(width, height);

 

}

 

 

 

I originally had

 

 

 

 

 

 

 

 

 

 

 

 

protected void sublayout(int width, int height) {

 

 

    super.sublayout(width, height);

    userText.setWidth( );

}

 

which would explain the reason that the settings were always a rotation behind. doh! lol