I have tried it overriding paint() method inside my own class which extends LabelField, but I ignore if there is another simpler way.
My code:
protected void paint(Graphics graphics) {
int previousColor = graphics.getColor();
graphics.setColor(0xFFFFFF);
graphics.drawText(getText(), 2, -2);
graphics.setColor(previousColor);
super.paint(graphics);
}
What I want to achieve is this:
EDIT: The answer by Abhisek produces the following result, in case anyone is interested:
If Abhishek's answer does not work, you can try to do it directly in the paint method. It's easy, just paint it once in the bg color, then paint it again over it (a few pixels down and left the previous text) in the fg color. Something like this:
protected void paint(Graphics graphics) {
graphics.setColor(0xFFFFFF);
graphics.drawText(getText(), 2, 0);
graphics.setColor(0x000000);
graphics.drawText(getText(), 0, 2);
}
Notice how you need 2 extra pixels of height and width, so probably you'll have to override getPreferredWidth, getPreferredHeight and/or layout.
A stab in the dark, but try deriving a font using Font.derive(style, height, units, aAntialiasMode, aEffects), pass Font.DROP_SHADOW_RIGHT_EFFECT in the aEffects parameter and apply it to the field in question.
Do tell us if it works; I haven't used it since it's undocumented!
Related
I am using ObjectChoiceField example. it is showing drop down at the end of right side, but i need to show some margin on the left side .
how we can achieve this ?
String choices[] = {"Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday", "Sunday"};
int iSetTo = 0;
VerticalFieldManager vfm=new VerticalFieldManager(){
protected void paint(Graphics graphics) {
graphics.setBackgroundColor(Color.BLACK);
graphics.clear();
super.paint(graphics);
}
};
vfm.add(new ObjectChoiceField("Day of the week",choices,iSetTo){
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
});
I am using this example:
![enter image description here][1]
You can do this with many fields by setting their margin. Field#setMargin() has been available since BBOS 6.0 officially, but was undocumented and usable in 5.0 (at least), too. So, at this point, I consider it perfectly acceptable to use in 5.0+ apps.
For example:
public ChoiceMarginScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
String choices[] = {"Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday", "Sunday"};
int iSetTo = 0;
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
ObjectChoiceField days = new ObjectChoiceField("Day of the week", choices, iSetTo) {
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
};
// set margin XYEdges(top, right, bottom, left):
days.setMargin(new XYEdges(0, 150, 0, 0));
vfm.add(days);
add(vfm);
}
Note that you also don't need to override the VerticalFieldManager#paint() method just to set a solid background color. You can use setBackground() for that. For setting the white font color on your object choice field, though, overriding paint() is a fine solution.
Also: I just went off your screen shot, and assumed you wanted the choice field moved to the left, but with no other field to the right of it. If you want the choice field to the left to make room for another field on its right, then you probably want to put both those fields in a HorizontalFieldManager, representing a row, and then add that HorizontalFieldManager to your VerticalFieldManager. But, that's not what you showed, so I offer my answer above.
Developing on the blackberry (OS 7.0) and I have an extended Vertical Field manager created as such:
_myVFM = new MyViewManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT | Manager.VERTICAL_SCROLL){};
However, when I scroll the view, the virtual scroll view size appears way too big.
i.e, I can scroll quite alot further down than is needed and I cant work out why?
Any body any quick ideas? I do have a background image in there that is created as such:
public void paint(Graphics graphics)
{
Bitmap backgroundBitmap = Bitmap.getBitmapResource("bg.png");
Bitmap newBackground = new Bitmap(Display.getWidth(), Display.getHeight());
backgroundBitmap.scaleInto(newBackground, Bitmap.FILTER_LANCZOS, Bitmap.SCALE_TO_FILL);
graphics.clear();
graphics.drawBitmap(0, 0, Display.getWidth(),
Display.getHeight(), newBackground, 0, 0);
super.paint(graphics);
}
Please and thanks,
Burrows
You can redefine the method to define the height of the manager
protected void setExtent(int width, int height) {
super.setExtent(width, myHeight);
}
To not repeat the background image is necessary to redefine the following method, returning false
protected boolean isScrollCopyable() {
return false;
}
Another comment is that it is a bad practice to obtain an image from the paint method. What you are doing is every time you call the paint method is going to get this image.
It's best to get the image once and then use it.
public MyScreen() {
super(NO_VERTICAL_SCROLL);
I managed to fix the issue in my extension of MainScreen using 'NO_VERTICAL_SCROLL' style parameter
Combined with Rupak's suggestion of setting the Background in the constructor of my Vertical Field Manager rather than overriding paint (
https://gist.github.com/3248319)
everything seems Good now - thanks all for your help.
Burrows
No need to USE_ALL_HEIGHT in your constructor.
// instead use this
_myVFM = new MyViewManager(Manager.USE_ALL_WIDTH | Manager.VERTICAL_SCROLL){};
I am developing a blackberry app and I am new to Blackberry. I am using Label Field in every screens, but there is a color surrounding the LabelField other than the background I have given for the screen like the image I have given here..
This is a header in my App,which comes in every screens. Here you can see a white color around the "state editions". It does not look good. I want the orange background color at the place of white color. Thanks in advance...
You are using the following code.. (from your comment)
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER) {
public void paint(Graphics graphics) {
graphics.clear();
graphics.setColor(Color.BLACK);
graphics.setBackgroundColor(Color.ORANGE); graphics.fillRect(0, 0,0, 0);
super.paint(graphics);
}
};
Try to modify this like the following:
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER) {
public void paint(Graphics graphics) {
super.paint(graphics);
}
};
That means, you don't have to extend default LabelField.
Just use,
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER);
And check the Graphics , graphics.clear() etc in the API.
I am trying to draw a border around two text boxes, which works if I leave background colour of the main screen alone. The client's spec's call for a colour scheme with a blue background. When the EditFields are drawn to the screen, they appear as one field that spans the screen. There are 2 since each gets focus when it's supposed two and everything works otherwise. The two EditFields are then added to a GridFieldManager to control the layout.
I am subclassing the EditFields and adding the border around each of the EXEditFields, like so:
public class EXEditField extends EditField {
...
private void init( MainScreen scrn ) {
if ( this.hasVirtualKeyboard() )
this.vkbd = scrn.getVirtualKeyboard();
this.setMaxSize( this.MAX_CHARS );
this.setBorder( BorderFactory.createRoundedBorder(new XYEdges(0,0,0,0), Border.STYLE_SOLID) );
this.setBackground( BackgroundFactory.createSolidBackground(Color.WHITE) );
//this.setPadding( 3, 3, 3, 3 );
//this.setMargin( 0, 3, 0, 3 );
}
...
} // end class
Any help is greatly appreciated since there is not much in the way good Blackberry reference docs.
Ok, check this.
It is an open source library that provides some custom BlackBerry fields, including an EditField, with custom borders. You should be able to modify the code to display the borders you want.
You might try changing the paintBackground method within your custom EditField, try putting this code into your EditField class:
protected void paintBackground(Graphics graphics) {
graphics.setColor(Color.BLACK);
graphics.drawRect(0, 0, getWidth(), getHeight());
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, getWidth(), getHeight());
}
Trying to add a background image to a textfield but when a user types over and goes into a horizontal scroll the image seems to be replicated over causing it to look like the following:
Basically i want the 1st textfield to look like the 2nd after the user has inputed a large value. I have a class that extends horizontalfieldManager and in my paint function is the following:
protected void paint(Graphics g)
{
g.clear();
if (mLabelMode)
{
g.setColor(mLabelColor);
}
else
{
g.setColor(mColor);
}
int x = this.getHorizontalScroll();
g.drawImage(x, 0, mBackground.getWidth(), mBackground.getHeight(), mBackground, 0, 0, 0);
super.paint(g);
}
Any help would be greatly appreciated.
have a look at this:
Using image for a TextEditField in Blackberry