BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 11-23-2009, 11:25 PM   #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

Parmanent Unlock code for BlackBerry - PRIV 4G
Parmanent Unlock code for BlackBerry - PRIV 4G  pictureParmanent Unlock code for BlackBerry - Z30 GSM 4G
Parmanent Unlock code for BlackBerry - Z30 GSM 4G pictureEgrow 200 pcs Blackberry Fruit Seeds Home Garden Plantting Perennial Potted Swe
Egrow 200 pcs Blackberry Fruit Seeds Home Garden Plantting Perennial Potted Swe pictureTECH RIM STANDARDS EC50G-N-1-0-0-0-0-ACA238M-3-R-45-2, POWER CLAMP #246309
TECH RIM STANDARDS EC50G-N-1-0-0-0-0-ACA238M-3-R-45-2, POWER CLAMP #246309 pictureGOOD Chimera Dongle for All Modules Samsung HTC BLACKBERRY NOKIA LG HUAWEI
GOOD Chimera Dongle for All Modules Samsung HTC BLACKBERRY NOKIA LG HUAWEI picture

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