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

Posts: 70
Registered: ‎08-10-2009
My Device: Not Specified

GaugeField.getValue() - relation to position [pixel ] on screen

GaugeField.getValue() - relation to position [pixel ] on screen


How can one correlate the current progress of a gauge field with it's [pixel / x-coordinate] position on Display ?



Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-, Z10 (STL100-3)-, Z30 (STA100-5)-, Passport (SQW100-1)-, PlayBook (16GB)-
My Carrier: Verizon

Re: GaugeField.getValue() - relation to position [pixel ] on screen

[ Edited ]

getValue returns the current GaugeField value, so if you say min: 1, max: 5 and the bar is in the middle then the value should be 3. It does not return the pixel location on the screen.


To figure that out you need the field's X location on the screen, width, number or "ticks" and the current value.


width / tick count = tick width

(value - tick min) * tick width = current relative position

current relative position + GaugeField X location = current absolute position


tick count = getValueMax - getValueMin

width/X = getContentRect (then get X and width from that)


so in the end:

public static int getGaugeFieldBarPos(GaugeField gauge)
    XYRect rect = gauge = getContentRect();
    return rect.x + ((rect.width / (gauge.getValueMax() - gauge.getValueMin())) * (gauge.getValue() - gauge.getValueMin()));

That should do the trick though know that I never actually tested it.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.