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
Developer
B-Developed
Posts: 98
Registered: ‎12-29-2009
My Device: Bold
My Carrier: Rogers

EditField--No Wrap--Text Select--Error

 

Hi,

 

I have created an EditField and using some code posted in another post I 'disabled' the EditField's wrap feature so that when I enter text, the text continues on the same line.

 

The trouble is that when I try to select all of the text--by holding "Shift" and then moving the trackwheel up--I get an error "Stack Overflow"

 

My code is below.

 

Any ideas why I'm getting this error, or how I can 're-enable' the "Shift+Trackwheel" text selecting capability?

 

 

public void paint(Graphics g){
	//set background color
         g.setBackgroundColor(_bgColorSearchTextBox);				g.clear();
		
         //set border color and create border
         int bordercolor = Color.BLACK;
	int iRectX = getFont().getAdvance(getLabel())-1;
	g.drawRect(iRectX, -1, 251, 31);
				 
	//code for no-wrap text entry
	String entireText = this.getText();
			        
         String textToDraw = "";
	int width = this.getWidth();
         Font font = getFont();
	int availableWidth = width;
         if (font.getAdvance(entireText) <= availableWidth)
	{
	     textToDraw = entireText;
         }
         else
	{
	     int endIndex = entireText.length();
              for (int beginIndex = 1; beginIndex < endIndex; beginIndex++)
         {
              textToDraw = entireText.substring(beginIndex);
         if (font.getAdvance(textToDraw) <= availableWidth)
         {
	break;
}
}
}   
			        
this.setText(textToDraw);
super.paint(g);
}

 

Please use plain text.
Developer
jack_black
Posts: 74
Registered: ‎01-03-2010
My Device: Not Specified

Re: EditField--No Wrap--Text Select--Error

check this portion carefully:

 

int width = this.getWidth();
  Font font = getFont();
 int availableWidth = width;
  if (font.getAdvance(entireText) <= availableWidth)


Please use plain text.
Developer
B-Developed
Posts: 98
Registered: ‎12-29-2009
My Device: Bold
My Carrier: Rogers

Re: EditField--No Wrap--Text Select--Error

Do you think I am missing a critical piece of code in that if statement?  A piece that might be required to select all of the text?

 

I'm not sure what is wrong or missing with what I already have.

 

Any ideas?

Please use plain text.
Developer
NiceNix
Posts: 73
Registered: ‎10-23-2009
My Device: Not Specified

Re: EditField--No Wrap--Text Select--Error

I'm not sure why you are getting the Stack Overflow, but you can probably get around the problem by overiding the trackwheel event handler and forcing the shift, scroll-up so it acts like select all.

 

Just a thought.

~NN

Please use plain text.
Developer
B-Developed
Posts: 98
Registered: ‎12-29-2009
My Device: Bold
My Carrier: Rogers

Re: EditField--No Wrap--Text Select--Error

Cool--perhaps by just catching the characters that are press (i.e., 'shift'+trackwheel-left, right, up, or down)?

 

I'll give that a shot.

 

Please use plain text.
New Contributor
wanttolearn
Posts: 8
Registered: ‎04-14-2010
My Device: 8900-Bold
My Carrier: vcb

Re: EditField--No Wrap--Text Select--Error

hi, i also facing the same problem.....did u fix it

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: EditField--No Wrap--Text Select--Error

Sorry just looked at this code. 

 

This code is, in my opinion, dangerous.  You should not be calling setText from within paint - in paint you just do that, paint.  You should not change the Field contents.

 

If you want to do something like this, then override setText() and setFont().

 

So @ wanttolearn, I would ignore this code and problem completely, write your own code that does this, and then ask the question in a separate Thread. 

Please use plain text.
New Contributor
wanttolearn
Posts: 8
Registered: ‎04-14-2010
My Device: 8900-Bold
My Carrier: vcb

Re: EditField--No Wrap--Text Select--Error

hi

 

I am new to BB.Is there any other way  of doing the above......

 

ie)As of now i couldnt move the cursor when the user enter above 20 chars.....If it is 20 or below 20,i can move the cursor......

 

I want to move the cursor even the user enters more than 20 chars

Please use plain text.
New Contributor
wanttolearn
Posts: 8
Registered: ‎04-14-2010
My Device: 8900-Bold
My Carrier: vcb

Re: EditField--No Wrap--Text Select--Error

hi

 

thanks for the reply peter......

 

did u implement the above.............

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: EditField--No Wrap--Text Select--Error

I have never implemented anything like this.

 

I suggest you think carefully about what you really want to do, search the forum to make sure no one has asked fro something similar, and if not, start a new Thread explaining your problem. 

Please use plain text.