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
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

How to make a button with multiline text

Hello Sir

               How to make a Button with Multiline text.

thanks

Contributor
Posts: 43
Registered: ‎11-30-2011
My Device: Dev Alpha, 8520
My Carrier: Vodafone

Re: How to make a button with multiline text

You can't make the inbuilt ButtonField have multiple lines, you'll have to make your own field.

 

Try extending a simple LabelField, since it can support multiline text. Make it focusable and give it the desired amount of padding with the setPadding method and the desired Background/Border with setBackground/setBorder.

 

You'll have to override keyChar and navigationUnclick (and TouchEvent if you're developing for a touchscreen device) to put in button functionality.



I've got 99 problems and eclipse is all of them


Twitter

Contributor
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

Re: How to make a button with multiline text

thanks sir ,
but how to override Keychar and vavigationUnclick and touch event to make button from label field.please share me code.
Contributor
Posts: 43
Registered: ‎11-30-2011
My Device: Dev Alpha, 8520
My Carrier: Vodafone

Re: How to make a button with multiline text

code you ask for, and code you will get.

 

protected boolean navigationUnclick(int status, int time)
{
	if((status & KeypadListener.STATUS_FOUR_WAY) != 0 || (status & KeypadListener.STATUS_TRACKWHEEL) != 0)
	{
		onClick();
	}
	return true;
}

protected boolean keyChar(char character, int status, int time)
{
	if(character == Characters.ENTER)
	{
		onClick();
		return true;
	}
	return super.keyChar(character, status, time);
}

private void onClick()
{
	getChangeListener().fieldChanged(this, ACTION_INVOKE);
}

protected boolean touchEvent(TouchEvent message)
{
	int x = message.getX(1);
	int y = message.getY(1);
	
	if(message.getEvent() == TouchEvent.CLICK && (x >= 0 && x <= getWidth()) && (y >= 0 && y <= getHeight()))
	{
		onClick();
		return true;
	}
	return false;
}

 

I haven't tested it, but I'm pretty sure it will make it work similar to a ButtonField.

 

after this, just add a FieldChangeListener to the field using Field.setChangeListener to make it do what you want.



I've got 99 problems and eclipse is all of them


Twitter