BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 11-24-2009, 12:25 AM   #1 (permalink)
New Member
Join Date: Aug 2009
Model: 8310
Carrier: Vodafone
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Displaying Custom field screen.

Please Login to Remove!


I am new to Blackberry developement, i m trying to develop the custom fields & use them in my application.

I have developed simple LabelField & tried using it , but its not displaying in the screen.

I am creating the instance of CLabelField & adding it to VerticalFieldManager & then manager to DemoScreen, which extends MainScreen.

So pls look into the issue & let me know the problem.

If there are any free third party Custom fields with good look, are available pls let me know.

I am attaching my source code, pls have a look at this & let me know the problem.

package com.khan.uiApp;

import net.rim.device.api.ui.UiApplication;
import com.khan.screens.DemoScreen;

* @author Hidayath
public class CustomFieldsDemo extends UiApplication{

public CustomFieldsDemo()
System.out.println("CustomFieldsDemo.CustomFieldsD emo()");
pushScreen(new DemoScreen());
* @param args
public static void main(String[] args) {
CustomFieldsDemo demo = new CustomFieldsDemo();



package com.khan.screens;

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManag er;

import com.khan.customFields.CLabelField;
* @author Hidayath
public class DemoScreen extends MainScreen{

private CLabelField uName;
private VerticalFieldManager vfm;
public DemoScreen()
super.setTitle("Demo Screen");
vfm = new VerticalFieldManager();
uName = new CLabelField("Hidayath", 50,100);
uName.setDimensions(50, 20);
// add(uName);




package com.khan.customFields;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;

* @author Hidayath
public class CLabelField extends Field {

public static final int OFFSET=5;
private String label;
private int xPos, yPos;
private int _labelHeight;
private int _labelWidth;
private Font _font;

public CLabelField(String label, int xPos, int yPos) {
this.label = label;
this.xPos = xPos;
this.yPos = yPos;

public void setDimensions(int width, int height) {
this._labelWidth = width;
this._labelHeight = height;

protected void layout(int width, int height) {
// Update the cached font - in case it has been changed.
_font = getFont();
_labelHeight = _font.getHeight();
_labelWidth = _font.getAdvance(this.label);

// Calc width.
System.out.println("bwidth ::"+width+" height::"+height);
width = Math.min(width, getPreferredWidth());

// Calc height.
height = Math.min(height, getPreferredHeight());

System.out.println("width ::"+width+" height::"+height);
// Set dimensions.
setExtent(width, height);

protected void paint(Graphics g)
// g.setBackgroundColor(Color.BLUE);
g.fillRect(this.xPos, this.yPos, this._labelWidth, this._labelWidth);
g.drawText(this.label, this.xPos+OFFSET, this.yPos+OFFSET);

public int getPreferredWidth() {
return this._labelWidth;

public int getPreferredHeight() {
return this._labelHeight;

Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

MEIVAC SCV - 7.55 Industrial Heavy Duty Variable VM Vacuum Capacitor 7.5kV-500pF
MEIVAC SCV - 7.55 Industrial Heavy Duty Variable VM Vacuum Capacitor 7.5kV-500pF pictureMicromanipulator 2550 Vacuum Base Probe Manipulator Tag #47
Micromanipulator 2550 Vacuum Base Probe Manipulator  Tag #47 pictureFJC 6014 Vacuum Pump Adapter 1/4 inch flare female x 1/2 inch Acme male New
FJC 6014 Vacuum Pump Adapter 1/4 inch flare female x 1/2 inch Acme male New pictureThermal Engineering Co Thermistor Vacuum Gauge Model 4501 Microns
Thermal Engineering Co Thermistor Vacuum Gauge Model 4501 Microns pictureEdwards vacuum pump EXT-255H
Edwards vacuum pump EXT-255H picture

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.