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
rihan007
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

drawRect line thickness

Hello all,

 

I want to draw a rectangle with drawrect. i draw it using the following code.

 

 

graphics.drawRect(0, yForTitleToDraw, hfm.getWidth(), heightForTitleToDraw); 

 

i need to increase the thickness of the line which draws the rectangle so the border line is thicker. How to do it friends?

 

 

Developer
simon_hain
Posts: 16,347
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: drawRect line thickness

you cannot. use it multiple times with adjusted values.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
zany
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: drawRect line thickness

are you want to draw thick lines over all the edges of the field? why cant you use border for that field by specifying the thickness of the border

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Developer
haagmm
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: drawRect line thickness

I have an answer.  you will not like it.

 

Step 1 : Create a graphics object based on a bitmap transparent zeroed bitmap

Step 2 : Fill a rectangle of the size and color you want.

Step 3 : Fill a smaller rectangle of the size of the interior transparent region with a marked color

Step 4 : get the ARGB of the bitmap

Step 5 : Itterate through the ARGB setting all instances of the marked color to 0x0. 

Step 6 : reset the ARGB to the Bitmap object

Step 7 : Blit the Bitmap to the screen.

 

And THAT is how you draw a thicker rectangle.

 

Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: drawRect line thickness

how about with fillRect???

 

here is the sample... i hope it meets your requirement...

 

graphics.fillRect(0, 0, 2, height); //Left border
	         graphics.fillRect(0, 0, width, 2); //Top border
	         graphics.fillRect(width-2, 0, 2, height); //Right border
	         graphics.fillRect(0, height-2, width, 2); //Bottom border

 

 

Thanks and Regards,
PraveenGoparaju.
Developer
jack_black
Posts: 74
Registered: ‎01-03-2010
My Device: Not Specified

Re: drawRect line thickness

if you use higher OS versions then you may use borderfactory, decor classes

from 4.6 on ward

 

net.rim.device.api.ui.decor

net.rim.device.api.ui.decor.Border

net.rim.device.api.ui.decor.BorderFactory

 

 

 

 

mark it when solved and give kudoes to who help you

Developer
fwest
Posts: 67
Registered: ‎10-14-2009
My Device: Not Specified

Re: drawRect line thickness

@simon: ever tried that with rounded borders and got it to look good? i've had "empty" pixels between the 2 lines alot

 

best way to do it is to draw a filled rect and then another one that's x pxl less in height/width from my experience

-------------
blog: http://coding.westreicher.org
twitter: http://www.twitter.com/meredrica
Developer
haagmm
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: drawRect line thickness

fwest, in truth thick rounded borders the only way i know how to do is either with drawFilledPath and Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT  or the way i mentioned above. 

 

Developer
haagmm
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: drawRect line thickness

Ok After some hacking around this afternoon i got it. 

 

 

	protected void paintBackground(Graphics arg0) {
		// TODO Auto-generated method stub
		super.paintBackground(arg0);
		arg0.setBackgroundColor(Color.BLUE);
		arg0.clear();
		arg0.setColor(Color.BLACK);
		int width = getWidth();
		int height = getHeight();
		int offset = 10;
		int inside = 5;

		int [] xPts = new int[]{0,0,offset,width-offset,width,width,width,width,width-offset,offset,0,0,0,
				inside,inside,inside+offset,width-offset-inside,width-inside,width-inside,
				width-inside,width-inside,width-inside-offset,inside+offset,inside,inside,inside	
			};
		int [] yPts = new int[]{offset,0,0,0,0,offset,height-offset,height,height,height,height,height-offset,offset,
				offset+inside,inside,inside,inside,inside,offset+inside,
				height-offset-inside,height-inside,height-inside,height-inside,
				height-inside,height-offset-inside,offset+inside};
		byte [] pointTypes  = new byte[]{
				Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,Graphics.CURVEDPATH_END_POINT,
				Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,Graphics.CURVEDPATH_END_POINT,
				Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,Graphics.CURVEDPATH_END_POINT,
				Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_END_POINT,
				Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,Graphics.CURVEDPATH_END_POINT,
				Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,Graphics.CURVEDPATH_END_POINT,
				Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,Graphics.CURVEDPATH_END_POINT,
				Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,Graphics.CURVEDPATH_END_POINT,Graphics.CURVEDPATH_END_POINT};
		arg0.drawFilledPath(xPts, yPts, pointTypes, null);

		
	}