0

Why use Math.min in below overridden method ?

   protected void layout(int width, int height) 
    {
        setExtent(Math.min( width, getPreferredWidth()), Math.min( height, getPreferredHeight()));
    }

I seen this code in this question - BlackBerry - ButtonField with centered Bitmap

Community
  • 1
  • 1
blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • For lack of any other information on your expectations, it's there because the appropriate extent to set is the minimum of the two available values from `width` and `getPreferredWidth`, and similarly for height. – Damien_The_Unbeliever May 21 '11 at 15:28
  • Reason im asking is that I'm getting a line of unpainted pixels horizontally acrross the screen when I add my verticalfieldmanager and I think its something to do me not using math.min when setting the extent (I recall recall reading this somewhere before, not sure where). – blue-sky May 21 '11 at 15:34
  • 2
    Do you not think then, that it would be better to post a question concerning a line of unpainted pixels, hopefully a reasonably complete sample of the problem (for others to reproduce on their machines), and then to ask whether the above code could be relevant, or in which way you suspect it is relevant? (Or, to be fair, I'd rather you edit this question to do these, rather than post a new one). – Damien_The_Unbeliever May 21 '11 at 15:39
  • I just want to know what would be a valid context to use the above implementation of layout method, maybe I should have specified this in the original question. I've seen this used in examples before and I'd like to know what are the reason(s) a developer would override layout in this way. – blue-sky May 21 '11 at 15:45

1 Answers1

1

I found this helpful - http://supportforums.blackberry.com/t5/Java-Development/Question-Regarding-setExtent-and-getPreferredWidth-for-Custom/td-p/469886

"Note that the values used for setExtent should never be larger than the values passed in to layout. These are the maximum extent available to the field."

blue-sky
  • 51,962
  • 152
  • 427
  • 752