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
Trusted Contributor
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified
Accepted Solution

Implement Text Area

Hi,

I need to implement Text Area in my app. I created custom textbox its working well, when enter key is pressed i am not getting second line but the focus goes to next field. Please

class TextBox extends VerticalFieldManager {	
	int managerWidth;
	int managerHeight;
	private EditField editField;

	int width = Display.getWidth()-70;
	int height = 18;
	int maxvalue=2000;
	public TextBox() {
		super(Manager.NO_VERTICAL_SCROLL);
		managerWidth = width;
		managerHeight = height;
		VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | 				VerticalFieldManager.FIELD_VCENTER);
		// vfm.setPadding(3,0,0,5);    
		editField = new EditField("","",maxvalue,Field.FIELD_HCENTER){
			public void paint(Graphics g) {
				getManager().invalidate();
				this.setFont(Utilities.getAppFont());
				super.paint(g);
			}
		};
		vfm.add(editField);
		add(vfm);
	}    	
	public void paint(Graphics graphics) {
		graphics.setColor(Color.WHITE);
		graphics.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
		graphics.setColor(0x00000000);
		super.paint(graphics);
		graphics.setColor(0x0BBBBBB);		
		graphics.drawRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
	}
	public void sublayout(int width, int iHeight) {		
		if (managerWidth == 0) {
			managerWidth = width;
		}
		if (managerHeight == 0) {
			managerHeight = iHeight;
		}
		super.sublayout(managerWidth, managerHeight);
		int iNumFields = getFieldCount();
		int iYPos = 5; 
		int iXPos = 5;
		Field fField = null;

		for (int i = 0; i < iNumFields; i++) {
			fField = this.getField(i);			
			setPositionChild(fField, iXPos, iYPos);
			//get height for layout and height
			int tmpHeight = managerHeight;
			//draw field
			layoutChild(fField, getWidth(), tmpHeight);
			iYPos = iYPos + tmpHeight+5;
		}
		//now we reset our extent to include padding   

		this.setExtent(managerWidth, Math.max(iYPos, getPreferredHeight()));
		setVirtualExtent(managerWidth, Math.max(iYPos, getPreferredHeight()));
	}
	public int getPreferredHeight() {
		height = 5;
		int iNumFields = getFieldCount();
		for (int i = 0; i < iNumFields; i++) {
			height += getHeight(getField(i))+5;
		}
		return height;
	}

	private int getHeight(Field f) {
		return Math.max(Math.max(f.getContentHeight(), f.getHeight()),f.getPreferredHeight());
	}
	public String getText() {		
		return editField.getText();
	}
	public void setText(String text) {
		editField.setText(text);
	}
	public void setMaxSize(int max) {
		editField.setMaxSize(max);
	}  

}

 

Help me to create text area

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: Implement Text Area

Sorry not looked seriously at your code, but there are some issues with it I think.

 

Rather than try to correct your code, does this do the job for you?

 

http://supportforums.blackberry.com/t5/Java-Development/TextBoxField-revisited/ta-p/548410

Trusted Contributor
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Implement Text Area

Thanks for your reply and suggestions Peter, Myself implemented textarea by using AutoTextEditField instead of Editfield. And i will follow your link and retify my mistakes soon.

 

Thanks you.

Trusted Contributor
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Implement Text Area

Hai to all,
Again I struck with the custom Textbox, I followed above link and creted Textbox, its working well but when i entered text, i am getting underline below the text. Please help me.9000.jpg

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Implement Text Area

 

Hi @,

 

It looks like the underline of the dictionary feature...

Try adding NO_LEARNING style flag in the constructor.

 

Do note that I haven't tried this on my own.

 

Hope that helps,

 

E.

Trusted Contributor
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Implement Text Area

Yes you are correct maadani, Underline comes only for non dict words. I tried no learning but no use still the issue persists.

Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry

Re: Implement Text Area

Hi Peter,

 

Thanks.. its useful to build text area... how to set value for this text area. Like i want to display "Welcome to Blackberry" in text area. How to set the String?

 

Thanks...