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
Contributor
dsailer
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:
    	//http://supportforums.blackberry.com/t5/Java-Development/Stop-edit-field-from-wrapping-text/m-p/25522...
		this.textboxWidth = maxWidth;
    	int maxNumChars = maxWidth/getFont().getAdvance("M");
		this.setMaxSize(maxNumChars);

		//i should be able to let BasicEditField do this...
		super.layout(maxWidth, maxHeight);
    }
    
    public void init() {
    	setText(INITIAL_TEXT);
    	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) {
			setText("");
			initialState = false;
			fontColor = Color.BLACK;
		}

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

        g.setColor(Color.WHITE);
        //x,y,width,height,arcWidth,arcHeight
        g.fillRoundRect(0, 0, textboxWidth, fontHeight, cornerRadius,cornerRadius);
        
        g.setColor(Color.LIGHTGREY);
        g.drawRoundRect(0, 0, textboxWidth, fontHeight, cornerRadius,cornerRadius);
        
        g.setColor(fontColor);
        g.drawText(getText(), 0, 0);
      
        super.paint(g);
    }

}

 

 

Please use plain text.