How to set Rounded Border for Blackberry BitmapField - blackberry

I trying to set rounded border for Blackberry Bitmap field.But it is not working for me.
I overriding paint method of Bitmap field.
g.drawRoundRect(0,0,HomeScreenIcons.barcode.getWidth(),HomeScreenIcons.barcode.getHeight(), 10, 10);
How can i set Border for Bitmap field in Blackberry.

You can give a try this way:
BitmapField bitf = new BitmapField();
bitf.setBorder(BorderFactory.createRoundedBorder(new XYEdges(6,6,6,6)));
Hope this helps...

Related

Actionscript: Tile image like background repeat-x

var bar:Sprite=new Sprite();
bar.graphics.clear();
var y:*=stage.stageHeight-(el.sprite.height+margin);
bar.graphics.beginBitmapFill((el.sprite.content as Bitmap).bitmapData);
bar.graphics.drawRect(margin,y,stage.stageWidth-margin*2,el.sprite.height);
bar.graphics.endFill();
el.sprite is Loader instance.
Image to repeat-x
I'm getting strange rendering results:
What i'm doing wrong?
Updated post
I'm not sure what you're trying to do with the margin/y values, but if you want the bitmap to repeat inside the container, starting at x=y=0, then the following works:
var bar:Sprite = new Sprite();
bar.graphics.beginBitmapFill((el.sprite.content as Bitmap).bitmapData);
bar.graphics.drawRect(0,0,desiredBarWidth, desiredBarHeight);
bar.graphics.endFill();
For any padding/margin, place the bar inside a container and position it that way. Of course, if you're using the first image (the gradient, not the arrow), you could simply do the following:
var bar:Sprite = new Sprite();
bar.addChild(el.sprite.content as Bitmap);
bar.width = desiredBarWidth;
This will stretch the bar and its contents to whatever width you specify - it's probably cleaner and more flexible if you're using a bitmap (such as the gradient) that doesn't change when stretched.
Changing to this, helped me. But i still don't understand. What was the issue?
bar.graphics.clear();
var y:*=stage.stageHeight-(el.sprite.height+margin);
bar.graphics.beginBitmapFill((el.sprite.content as Bitmap).bitmapData);
bar.graphics.drawRect(0,0,stage.stageWidth-margin*2,el.sprite.height);
bar.graphics.endFill();
bar.y=y;

BlackBerry textfield

I am trying to develop an application in which text is displayed on a background image.
Text must be displayed on an image and when the background image is changed text also must change.
To achive above requirement first you need to set Background image for your MainScreen for this there are more methods one is to override paint method of MainScreen.
Example code:
Bitmap screen1=Bitmap.getBitmapResource("Screen_1.jpg");
public void paint(Graphics graphics)
{
graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(),screen1, 0, 0);
super.paint(graphics);
}
};
After setting background image for screen you need to add LabelField or RichTextField to screen.
Example:
LabelField lf=new LabelField("text",Field.USE_ALL_WIDTH|DrawStyle.HCENTER);
add(lf);
When you need to change Backgound image set.
screen1=Bitmap.getBitmapResource("you image.jpg");
lf.setText("your labelfield text");
invalidate();
Hope this will help you.

Centering LabelField in HorizontalFieldManager in Blackberry

I added HorizontalFieldManager to screen with backgroundcolor and with specific width and height.And i added a labelField to hfm.But labelfield displaying at top in hfm.How can i adjust it to center.
Try This
LabelField.setMargin(Hfm height/2, 15, 0, 15);
Did you try to set the style of the labelfield to LabelField.Field_HCENTER? This should work for you

Create Transparent Mainscreen in Blackberry

i want to create a type of MainScreen in my Blackberry app which should be Transparen/Translucent.
I tried with following code on MyCustomMainScreen's constructor but it still shows a white screen
Background bg = BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 50);
this.setBackground(bg);
I have read in the forum and also tested it for popup screens and it works fine with them but fails with mainscreens.
Does anyone have any idea how to achieve this for MainScreen..?
-Big O
override the paint method like:
class M extends MainScreen
{
public M()
{
setBackground(BackgroundFactory.createSolidTransparentBackground(Color.ANTIQUEWHITE, 100));
LabelField l=new LabelField("hello");
add(l);
}
protected void paint(Graphics graphics)
{
super.subpaint(graphics);
}
}
Instead of
Background bg = BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 50);
this.setBackground(bg);
maybe better
Background bg = BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 50);
getMainManager().setBackground(bg);
I found the solution without overriding the paint method. You need to set the background full transparent for the Screen and translucent for the main manager:
// Full transparent background
setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
// Manager translucent background
getMainManager().setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 50));

How can I show a textbox on my BlackBerry application?

How can I add a textbox so a user can enter numeric values into my form? I need the borders of the textbox control to be visible at all time.
Thanks.
You should implement your own class, inherited from TextBox and override void paint(Graphics g) method.
Smth, like that, sorry i write from mobile:
public void paint(Graphics g)
{
// set color
g.setColor(0x555555);
// draw 100*100 rectangle
g.drawRect(0, 0, 100, 100);
// dont forget to invoke
super.paint(g);
}
If you dont want use overriding,
In OS 4.6+ you can use Border and BorderFactory classes (search in All Classes list).
// Each integer represents the amount of space between the box and border
// The four parameters of an XYEdge object represents each edge,
XYEdges thickPadding = new XYEdges(10, 10, 10, 10);
// Sample text field with a thick and solid rounded border
// and single solid colour background.
RichTextField simpleField = new RichTextField("Solid rounded border, solid background");
// Create border and background objects
Border roundedBorder = BorderFactory.createRoundedBorder(thickPadding, Border.STYLE_SOLID);
// Set the objects for use
simpleField.setBorder(roundedBorder);
// Add the field to the screen
add(simpleField);

Resources