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: 25
Registered: ‎02-19-2010
My Device: bold 9700
My Carrier: att

missing cursor, custom EditField

In the following example, the call to fillRoundRect in paint() makes the cursor invisible. Is there any way to fix this?(short of drawing it myself)





package com.mzinga.ui.discussions.fields;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.EditField;

 * A rectangle with round corners
public class SearchTextField extends EditField {

    private int textboxWidth;

    private int fontHeight;
    private static final int INITIAL_FONT_COLOR = Color.LIGHTGREY;
    private int fontColor = INITIAL_FONT_COLOR;
    private int cornerRadius = 10;
    private boolean initialState = true;
    private static final String INITIAL_TEXT = "Search";
	public SearchTextField()
		super("", INITIAL_TEXT);
		fontHeight = getFont().getHeight();

    public void layout(int maxWidth, int maxHeight) {
    	//figure out how many chars would fit and limit the length to that. 
    	//I'd rather just keep it from wrapping but I need some more specialized code for that:
		this.textboxWidth = maxWidth;
    	int maxNumChars = maxWidth/getFont().getAdvance("M");

		//i should be able to let BasicEditField do this...
		super.layout(maxWidth, maxHeight);
    public void init() {
    	initialState = true;
    	fontColor = INITIAL_FONT_COLOR;
    //the initial user keystroke overlays the initial "search" text
	protected boolean keyChar(char c, int status, int time) {

		if (initialState) {
			initialState = false;
			fontColor = Color.BLACK;

		return super.keyChar(c, status, time);
    public void paint(Graphics g) {

        g.fillRoundRect(0, 0, textboxWidth, fontHeight, cornerRadius,cornerRadius);
        g.drawRoundRect(0, 0, textboxWidth, fontHeight, cornerRadius,cornerRadius);
        g.drawText(getText(), 0, 0);