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
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell
Accepted Solution

How can set the background color for status bar?

Quote from the previous forum:


Guest: Guest
How can set the background color for status bar?
Posted: Jul 17, 2008 2:56 AM
 
How can set the background color for status bar?
Using this code for Status Bar:
LabelField statusField = new LabelField("Good Morning" ,LabelField.USE_ALL_WIDTH | LabelField.NON_FOCUSABLE | LabelField.HCENTER)
{
int _backgroundColour = Color.LIGHTGREEN;
public void paint(Graphics g)
{
g.setBackgroundColor(Color.RED);
g.clear();
super.paint(g);
}
};

Font defaultfont = Font.getDefault();
Font smallfont = defaultfont.derive(Font.PLAIN, 12);

statusField.setFont(smallfont);
setStatus(statusField);


When I ran the code you have above, my status background colour was red.  Is this not what you are seeing?  If so, please provide the BlackBerry model and handheld software version you are testing with.  You can find this under Options, About.

 

Or if you are trying to do something else, please elaborate. 

 

I was testing this in the BlackBerry Simulator included with the version 4.5.0 BlackBerry JDE (4.5.0.44).

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
BBDev
Posts: 20
Registered: ‎07-17-2008
My Device: Not Specified

Re: How can set the background color for status bar?

I was testing this on JDE-4.1.0 (7290). Please tell me the solution for OS-4.1.
Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How can set the background color for status bar?

To do this in version 4.1, first call getColor and save the current colour.  Then call setColor, setting the colour to the colour you want to use for the background.  After that call call fillRect, starting at 0, 0 and going to the size of the field (use this.getWidth() and this.getHeight() to get this).  This should fill the entire field with your specified colour. 

 

To allow for drawing of the default field contents call setColor again, passing in the original color and then call super.paint.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
BBDev
Posts: 20
Registered: ‎07-17-2008
My Device: Not Specified

Re: How can set the background color for status bar?

Firstly Thanks MSohm. I used this scenario, it is very useful to me.But its tuck in one case.

Actually I am using statusBar to show the username, It can be long.So I am using this:

 

statusField = new LabelField(username,LabelField.FIELD_HCENTER|LabelField.HCENTER|LabelField.USE_ALL_HEIGHT|
        LabelField.NON_FOCUSABLE );

But when I am using this with paint():

statusField = new LabelField(" ",LabelField.FIELD_HCENTER|LabelField.HCENTER|LabelField.USE_ALL_HEIGHT|
        LabelField.NON_FOCUSABLE ){

      public void paint(Graphics g) {
                           int x=  g.getColor();
                           g.setColor(Color.LINEN);
                           g.fillRect(0,0,this.getWidth(),this.getHeight());
                           g.setColor(Color.BLUE);
                       super.paint(g);
                        }

};

 

It color only those area which is used by text. Please Help me to sort out this situation. 

 

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How can set the background color for status bar?

You can add the LabelField.USE_ALL_WIDTH style to your LabelField.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
BBDev
Posts: 20
Registered: ‎07-17-2008
My Device: Not Specified

Re: How can set the background color for status bar?

 

 I had already tried with this style but problem is there when user name is long and we want to show this username in multiline then it doesn't show this in multiline. For this we removed LabelField.USE_ALL_WIDTH and used LabelField.USE_ALL_HEIGHT.

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How can set the background color for status bar?

Can you post a screenshot of what you see versus what you are trying to accomplish?  Long strings should wrap to the next line even with the LabelField.USE_ALL_WIDTH and used LabelField.USE_ALL_HEIGHT styles set.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
jobincantony
Posts: 26
Registered: ‎08-04-2008
My Device: Not Specified

Re: How can set the background color for status bar?

[ Edited ]

Hi,

 

I too facing the same problem.

 

I have a custome labelfield and i want to use the objects of my labelfield as my Statusmessages in my application.

My application consists of 5 screens and i need to update the status messages of each screen depending on some  criteria.

 

 




****************************************************************

class BCSColoredStatusField extends LabelField
{
int color=Color.RED;
int bgColor= Color.ALICEBLUE;

/**
* Calling the Constructor of its Super class
* @param label String to be displayed
*/
public BCSColoredStatusField(String label)
{
super(label,LabelField.USE_ALL_WIDTH|LabelField.FIELD_HCENTER|LabelField.HCENTER|LabelField.USE_ALL_HEIGHT);
}

/**
* Calling the Constructor of its Super class
*/
public BCSColoredStatusField()
{
super("",LabelField.USE_ALL_WIDTH|LabelField.FIELD_HCENTER|LabelField.HCENTER|LabelField.USE_ALL_HEIGHT);
}

/**
* Coloring the Backgorund and Text of the field
* @param g graphics object
*/
public void paint(Graphics g)
{
g.getBackgroundColor();
g.setBackgroundColor(bgColor);
g.clear();
// g.fillRect(0,0,Graphics.getScreenWidth(),this.getHeight());
g.getColor();
g.setColor(color);
//g.setFont(g.getFont().derive(Font.BOLD));
super.paint(g);
}

/**
* Initialising with the data member color
* @param color color value to be shown
*/
public void setFontColor(int color)
{
this.color=color;
}
/**
* Initialising with the data member bgColor
* @param color color value to be shown
*/
public void setBackGroundColor(int bgColor)
{
this.bgColor = bgColor;
}
}

*************************************************************************

 


In myScreen class i have

 

private static BCSColoredStatusField statusLbl = new BCSColoredStatusField("Scanner not Connected");     

setStatus(statusLbl);  

 

then the expexted result is..Requirement

 

Expected Result/Requirement

 

But iin some screens i got the result as. output

 

Output

 

Could you please help me to solve this issue...

 

Thank You

 

Jobin

 

 

 

 

Message Edited by jobincantony on 08-04-2008 07:37 AM
Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How can set the background color for status bar?

I'm not able to see the screenshots you posted.  Can you provide alternative image links?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
jobincantony
Posts: 26
Registered: ‎08-04-2008
My Device: Not Specified

Re: How can set the background color for status bar?

[ Edited ]
Please use plain text.