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
Regular Contributor
Posts: 85
Registered: ‎11-18-2011
My Device: using eclipse
My Carrier: blackberry

Re: retrive the pixel value from the string entered in textfield

import net.rim.device.api.ui.Graphics.*;

import java.lang.Object;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.component.LabelField;
import java.util.Hashtable;
import net.rim.device.api.ui.container.MainScreen;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.TextField;
import net.rim.device.api.ui.Font;
import javax.microedition.lcdui.Form;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.FontMetrics;

public class Font1 extends UiApplication {

public static void main (String[] args)
{
Font1 F = new Font1();


F.enterEventDispatcher();
}

Font1()
{

pushScreen(new FontScreen());
}


public final int getAdvancetext(String text) {

return getAdvancetext(text);
}
}

class FontScreen extends MainScreen implements FieldChangeListener

{




protected static final String String = null;

FontScreen()
{

setTitle("Pixels");
add(new LabelField("Enter the Text"));
add(new SeparatorField());
final TextField autoT = new TextField("NAME: ", "");
try
{
FontFamily myFontFam = FontFamily.forName("SANS-SERIF");
Font myFont = myFontFam.getFont(Font.SANS_SERIF_STYLE, 35);
setFont(myFont);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
add(autoT);
final ButtonField mySubmitButton = new ButtonField("GET PIXEL HIGHT" ,ButtonField.CONSUME_CLICK);



add(mySubmitButton);


FieldChangeListener customListener = new FieldChangeListener()
{

public void fieldChanged(Field field, int context) {
if(field == mySubmitButton)
{
getPixels(null, null, context, context);
}

}

public int getPixels(String text,Font font,int fontsize,int availablePixelwidth)
{






//float points;
//float pixels;









// points = text.length();
// pixels = 72* points/60;
//Dialog.alert(String.valueOf(pixels));




//fontsize=autoT.;
//FontMetrics metrics = new FontMetrics();


//int a=metrics.getHeight();
//fontsize=Font.;;
//Dialog.alert(String.valueOf(pixels));

Font F=getFont();

//int a=cursorPosition.getAdvancewidth();


//text= autoT.getText();



//availablePixelwidth=Font.getAdvance(text);


//text=String.valueOf((cursorPosition));
//Dialog.alert(String.valueOf(a));
//FontMetrics metrics = new FontMetrics();
//{

//metrics.equals(autoT);


//availablePixelwidth=metrics.getHeight();
//Dialog.alert(String.valueOf(availablePixelwidth));
//Dialog.alert(String.valueOf(a));

//}





//availablePixelwidth=metrics.getHeight();
//Dialog.alert(String.valueOf(availablePixelwidth));


//Dialog.alert(String.valueOf(cursorPosition));
return availablePixelwidth;




}
};
mySubmitButton.setChangeListener(customListener);
}



public void fieldChanged(Field field, int context) {

}

}
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: retrive the pixel value from the string entered in textfield

try to use getAdvance, which i linked in my first post.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 85
Registered: ‎11-18-2011
My Device: using eclipse
My Carrier: blackberry

Re: retrive the pixel value from the string entered in textfield

whr to use getadvance methode sir..plz sir can u plz help me out i rlly b thnkful t u.
Regular Contributor
Posts: 85
Registered: ‎11-18-2011
My Device: using eclipse
My Carrier: blackberry

Re: retrive the pixel value from the string entered in textfield

look sir,,
i am using textfield ,
ok..
now when m enter string in textfield ..
how me get the value of pixels of my entered string.
can u plz define the full methode n procedure to retrieve the pixels value of my entred string..
i rlly be thnkful t u if u hlp me..
Regular Contributor
Posts: 85
Registered: ‎11-18-2011
My Device: using eclipse
My Carrier: blackberry

Re: retrive the pixel value from the string entered in textfield

i am post the full program can u help me sir.
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: retrive the pixel value from the string entered in textfield

can you please write full words?

use
http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/ui/component/BasicEditField.ht...
to get the text of the field.
use
http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/ui/Field.html#getFont()
to retrieve the font.
use http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/ui/Font.html#getAdvance(java.l... with the text you retrieved to get the width of the text.

if you need it in pixels you can calculate that with http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/system/Display.html#getHorizon... and http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/system/Display.html#getWidth()
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 85
Registered: ‎11-18-2011
My Device: using eclipse
My Carrier: blackberry

Re: retrive the pixel value from the string entered in textfield

sir,i am send u all the code,can you please mention where is my mistake,and why i am not retrive the pixels width n hight of string.
Trusted Contributor
Posts: 151
Registered: ‎06-17-2010
My Device: Curve 8900
My Carrier: Vodafone

Re: retrive the pixel value from the string entered in textfield

Use the code like

Font _font = Font.getDefault().derive(Font.BOLD, 25,
Ui.UNITS_px);
set this font to your text field string.

textfield.setfont(_font);

Now for retrieving height and width of that text.. use this syntax..

_textlHeight = _font.getHeight();
_textWidth = _font.getAdvance(_label);

 

FYK,


See dhiraj4545,
you are a developer so you have to clear with your logic and basic fundamentals of java.
At here we are provide you some hint to solve your problem not give you a full dish. ok..

and one another thing, first search your problem in forums, and if you not find any solution then create your thread, be in touch with support forum. This will Help you a lot.

I hope you can understand what i want to say.

 

Don't be frustrate when problem occur, but try to find out the solution. ok.. Make a Smiley Happy and back to work..

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

Regular Contributor
Posts: 85
Registered: ‎11-18-2011
My Device: using eclipse
My Carrier: blackberry

Re: retrive the pixel value from the string entered in textfield

sir can u define the meaning of Ui.UNITS_px.
me retrive the default hight but by using getadvance me only retrives always zero value.
Regular Contributor
Posts: 85
Registered: ‎11-18-2011
My Device: using eclipse
My Carrier: blackberry

Re: retrive the pixel value from the string entered in textfield

thnks albert_anks..its works now..
i rlly thnkful t you for this..
meet u again..and share some issues..