Java Reference
In-Depth Information
public int getMinContentWidth() {
// Loop through the values. Find the maximum width.
int maxWidth = 0;
for (int i = 0; i < mValues.size(); i++) {
String value = (String)mValues.elementAt(i);
int width = mFont.stringWidth(value);
maxWidth = Math.max(maxWidth, width);
}
// Don't forget about the title, although we don't
// really know what font is used for that.
int width = mFont.stringWidth(getLabel()) + 20;
maxWidth = Math.max(maxWidth, width);
return maxWidth;
}
public int getMinContentHeight() {
return mFont.getHeight();
}
public int getPrefContentWidth(int width) {
return getMinContentWidth();
}
public int getPrefContentHeight(int height) {
return getMinContentHeight();
}
public void paint(Graphics g, int w, int h) {
int fraction = mVisibleIndexTimesTen % 10;
int visibleIndex = (mVisibleIndexTimesTen - fraction) / 10;
String value = (String)mValues.elementAt(visibleIndex);
g.setFont(mFont);
int bc = mDisplay.getColor(Display.COLOR_BACKGROUND);
int fc = mDisplay.getColor(Display.COLOR_FOREGROUND);
if (mFocus == true) {
bc = mDisplay.getColor(Display.COLOR_HIGHLIGHTED_BACKGROUND);
fc = mDisplay.getColor(Display.COLOR_HIGHLIGHTED_FOREGROUND);
}
g.setColor(bc);
g.fillRect(0, 0, w, h);
g.setColor(fc);
// Simple case: visibleIndex is aligned on a single item.
if (fraction == 0) {
g.drawString(value, 0, 0, Graphics.TOP | Graphics.LEFT);
return;
}
Search WWH ::




Custom Search