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

Change the background color of a screen

by Retired on ‎02-12-2010 03:31 PM - edited on ‎06-01-2011 03:38 PM by Retired (15,637 Views)

Summary

 

This article applies to the following:

  • BlackBerry® Java® Development Environment (BlackBerry JDE)
  • BlackBerry smartphones based on Java® technology

Description

 

BlackBerry JDE 4.6.0 and later

 

The BlackBerry API version 4.6.0 introduces a set of décor APIs that allow a developer to more easily change the look and feel of their applications. This includes changing the background color of a screen and creating borders around managers. The following code uses these new APIs to create a screen with a red background with a grey border.

 

 

class DecorTestScreen extends MainScreen {

private VerticalFieldManager _manager;

DecorTestScreen() {
_manager = (VerticalFieldManager)getMainManager();

Background bg = BackgroundFactory.createSolidBackground(Color.RED);
_manager.setBackground(bg);

XYEdges edges = new XYEdges(20, 20, 20, 20);
Border border = BorderFactory.createBevelBorder(edges);
_manager.setBorder(border);

_manager.add(new LabelField("test"));
_manager.add(new LabelField("test 1"));
_manager.add(new LabelField("test 3"));

}
}

 

An example of a screen created by the code above is below.

 

DB-00131.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BlackBerry JDE 4.5.0 and earlier

 

To set the background color of a screen, use the setBackgoundColor(int color) method that is included within the Graphics class. The clear() method from the Graphics class must immediately follow the setBackgroundColor(int Color) method, as the entire graphic area must be cleared to allow other objects to be drawn. For example:

 

 

public void paint(Graphics graphics)
{
// Sets the BackgroundColor
graphics.setBackgroundColor(Color.DARKRED);

// Clears the entire graphic area to the current background
graphics.clear();
}

 

If you want to change the background color and add fields to the screen, such as a BasicEditField or a VerticalFieldManager, the graphics class changes the background color but the fields are not displayed on the screen. When creating a new instance of an object, you must override it, setting the background color with the code sample provided above. For example:

 

 

VerticalFieldManager mgr = new VerticalFieldManager(Manager.HORIZONTAL_SCROLL)
{
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.DARKRED);
graphics.clear();
super.paint(graphics);
}
};

 

Creating a new instance of VerticalFieldManager in the example above overrides the instance to change the entire background color for this field.

 

Note: The above can be applied to any of the standard managers (for example, DialogFieldManager, FlowFieldManager, HorizontalFieldManager, VerticalFieldManager).

Users Online
Currently online: 45 members 574 guests
Please welcome our newest community members: