CUSTOM TEXT FIELD PROBLEM
public class CustText extends TextField{ private String _text; private FontFamily _fontFamily1; private int _size, _color; private Font _headFont = null; public CustText(String _text, int _size,int _color, long _property) { super(_property); this._text = _text; this._size = _size; this._color = _color; } protected void paint(Graphics g) { try{ _fontFamily1 = FontFamily.forName("aerial"); } catch(ClassNotFoundException e) { _fontFamily1 = Font.getDefault().getFontFamily(); } _headFont = _fontFamily1.getFont(Font.PLAIN,_size); g.setColor(_color); g.setFont(_headFont); g.drawText(_text,0, 0); } }
I use the above code to customTextfield, the problem here is, when it is used to display long text that does not move to the next line, only the first line is painted, the rest of the lines are missing
Graphics.drawText draws text on a single line. This example allows input of multi line.
Tags: BlackBerry Developers
Similar Questions
-
focus with custom text field problem
Hello
I am new to BB dev., trying to write a small program with two CustomTextFields, but faceing the problem, then try to verify that CustomTextField is selected (the focus).
CustomTextField (NumericTextField)
import net.rim.device.api.ui.Manager; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.component.EditField; import net.rim.device.api.system.Display; import net.rim.device.api.system.Characters; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Font; public class NumericTextField extends Manager { private final static int DEFAULT_LEFT_MARGIN = 10; private final static int DEFAULT_RIGHT_MARGIN = 10; private final static int DEFAULT_TOP_MARGIN = 5; private final static int DEFAULT_BOTTOM_MARGIN = 5; private final static int DEFAULT_LEFT_PADDING = 10; private final static int DEFAULT_RIGHT_PADDING = 10; private final static int DEFAULT_TOP_PADDING = 5; private final static int DEFAULT_BOTTOM_PADDING = 5; private int topMargin = DEFAULT_TOP_MARGIN; private int bottomMargin = DEFAULT_BOTTOM_MARGIN; private int leftMargin = DEFAULT_LEFT_MARGIN; private int rightMargin = DEFAULT_RIGHT_MARGIN; private int topPadding = DEFAULT_TOP_PADDING; private int bottomPadding = DEFAULT_BOTTOM_PADDING; private int leftPadding = DEFAULT_LEFT_PADDING; private int rightPadding = DEFAULT_RIGHT_PADDING; private int totalHorizontalEmptySpace = leftMargin + leftPadding + rightPadding + rightMargin; private int totalVerticalEmptySpace = topMargin + topPadding + bottomPadding + bottomMargin; private int minHeight = getFont().getHeight() + totalVerticalEmptySpace; private int width = Display.getWidth(); private int height = minHeight; private EditField editField; public NumericTextField() { super(0); editField = new EditField(EditField.FILTER_REAL_NUMERIC); add(editField); } protected void sublayout(int width, int height) { Field field = getField(0); layoutChild(field, this.width - totalHorizontalEmptySpace, this.height - totalVerticalEmptySpace); setPositionChild(field, leftMargin+leftPadding, topMargin+topPadding); setExtent(this.width, this.height); } public void setTopMargin(int topMargin) { this.topMargin = topMargin; } public void setBottomMargin(int bottomMargin) { this.bottomMargin = bottomMargin; } protected void paint(Graphics graphics) { graphics.drawRoundRect(leftMargin, topMargin, width - (leftMargin+rightMargin), height - (topMargin+bottomMargin), 5, 5); boolean longText = false; EditField ef = (EditField)getField(0); String entireText = ef.getText(); String textToDraw = ""; Font font = getFont(); int availableWidth = width - totalHorizontalEmptySpace; if (font.getAdvance(entireText) <= availableWidth) { textToDraw = entireText; } else { int endIndex = entireText.length(); for (int beginIndex = 1; beginIndex < endIndex; beginIndex++) { textToDraw = entireText.substring(beginIndex); if (font.getAdvance(textToDraw) <= availableWidth) { longText = true; break; } } } if (longText == true) { ef.setText(textToDraw); super.paint(graphics); ef.setText(entireText); } else { super.paint(graphics); } } public int getPreferredWidth() { return width; } public int getPreferredHeight() { return height; } protected boolean keyChar(char ch, int status, int time) { if (ch == Characters.ENTER) { return true; } else { return super.keyChar(ch, status, time); } } public String getText() { return ((EditField)getField(0)).getText(); } public void setText(final String text) { ((EditField)getField(0)).setText(text); } }
and in my screen content trying to check:
NumericTextField focusImput() { NumericTextField focusField; if (_fieldFrom.isFocus()) { focusField = _fieldtFrom; } else { focusField = _fieldTo; } return focusField; }
but it always returns me _fieldTo...
NumericTextField definition:
_fieldFrom = new NumericTextField(); _fieldFrom.setChangeListener(this); manager.add(_fieldFrom); _fieldTo = new NumericTextField(); _fieldTo.setChangeListener(this); manager.add(_fieldTo);
Maybe someone to guide me how to correctly focus feature?
Thanks in advance.
Then you need two slightly customized EditFields - their main customization would be limiting their width, as well as making them focusable/unfocusable. So, something like this should work:
public class NumericTextField extends EditField { // override the constructors used in your code, adding FILTER_REAL_NUMERIC // ... private int maxWidth = Integer.MAX_VALUE >> 1; private boolean focusable = true; protected void layout(int width, int height) { super.layout(Math.min(maxWidth, width), height); } public void setMaxWidth(int width) { maxWidth = width; updateLayout(); } public boolean isFocusable() { return (isStyle(FOCUSABLE) & focusable); } public void setFocusable(boolean on) { focusable = on; } }
If you want to place the fields, use setMargin - he is documented in OS 6.0 but works since OS 4.2.
Use setMaxWidth to, well, set desired maximum width (otherwise EditField tenorman to the top of the entire available width). Use the setFocusable to toggle the field. In addition, you can play with the Visual States for the field you turn, but it's an exersize for another day. First of all make sure that it works and you know how to use it.
-
Slider custom text field (Cap) does not appear
All;
I created a custom text field based on the standard text field, changes work fine (really just a custom height and width and a border). The problem is the method of painting which seems to remove the cap of the field when it gets the focus. To be clear the carret never shown at all.
public class CustomText extends TextField //cutom text field width { //Custom Height and Width in Pixels final static int textwidth=125; final static int textheight=25; CustomText() { super(); // Call the default constructor //Border for text fields XYEdges padding = new XYEdges(5, 5, 5, 5); //space between box and border Border theborder = BorderFactory.createSimpleBorder(padding, Border.STYLE_SOLID); //Assign the border to the object this.setBorder(theborder); } public void onFocus( int direction ) { super.onFocus( direction ); //invoke parent procedure invalidate(); //mark for redraw } public void onUnfocus() { super.onUnfocus(); //invoke parent procedure invalidate(); //mark for redraw } //Override the layout with the custom Width and Height protected void layout(int width, int height) { super.layout(textwidth,textheight); setExtent(textwidth,textheight); } //Override the display message such that no message is displayed when the field is full protected void displayFieldFullMessage() { } //Override the default paint method to call the super class constructor and then assign the border protected void paint(Graphics graphics) { // int prevColor = graphics.getColor(); //Save Previous Color graphics.setBackgroundColor(Color.LIGHTGRAY); // Set to Gray graphics.clear(); // Clear for redraw super.paint(graphics); //Force Redraw of Object // graphics.setColor(prevColor); //restore for cursor paint } };
In the paint in the first and last method lines that are commented out were a soloution that I tried after reading on this subject. Something along the lines of the restoration of the default color, but unfortunately without success. Any ideas would be more useful
Thank you!
Quick thoughts:
(a) to remove the requirement to substitute paint by setting the background a Color.LIGHTGRAY using the base class
(b) you put on the field by using this:
Super.Layout (TextWidth, TextHeight);
If you then do the following:
setExtent (textwidth, textheight);
you are likely to confuse the field. If you still want to use the entire height and use the full width and then try to deal with it in the Style, that is, replace this:
Super(); Call the default constructor
with this
Super(TextField.USE_ALL_HEIGHT |) TextField.USE_ALL_WIDTH); Call the default constructor
(c) why you override onFocus and onUnfocus? I would like to delete these if you do not have anything specific to these methods.
Make these changes, and you'll have a more simple TextField. See if these changes will solve the problem of the caret too.
-
I want to implement a custom text field that displays its label on the leading edge of a line and its part editable on the TRAILING edge of the same way like a ChoiceField. Is there a documentation available to achieve this (maybe it's to say-sample code)? Or even if I could see the source code for ChoiceField. I develop for a Blackberry Pearl 8110 with 4.3.
I ended up solve this using managers of horizontal inside vertical management. I have to use a label field for the edit field that accompanies it. When lines are added, I followed is the width of the new label. Then in sublayout to align the edit fields according to the maximum width more stored a Variant. Could not align all the way to the right.
import net.rim.device.api.ui.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.text.*; public class MyLayoutManager extends VerticalFieldManager { protected int maxw; protected Font font; protected int font_height; private int size; public MyLayoutManager() { super(Field.USE_ALL_WIDTH); this.maxw = 0; this.font = Font.getDefault().derive(Font.PLAIN, 12); this.font_height = this.font.getHeight(); this.size = 0; } public void addLine(String label, int initial) { MyEditField mef = new MyEditField(label, initial); int label_width = this.font.getAdvance(label); this.maxw = Math.max(label_width, this.maxw); this.add(mef); this.size++; } public int getPreferredHeight() { return this.size * this.font_height; } public int getPreferredWidth() { return 240; } protected void sublayout(int maxwidth, int maxheight) { int y = 0; for (int i = 0; i < this.size; i++) { Field f = this.getField(i); this.setPositionChild(f, 0, y); this.layoutChild(f, 240, this.getPreferredHeight()); y += this.font_height; } this.setExtent(240, this.getPreferredHeight()); } protected class MyEditField extends HorizontalFieldManager { private LabelField the_label; private JunkField the_value; public MyEditField(String label, int initial) { super(Field.USE_ALL_WIDTH); this.the_label = new LabelField(label); this.the_label.setFont(font); this.the_value = new JunkField(initial + ""); this.the_value.setFont(font); this.add(this.the_label); this.add(this.the_value); } public int getPreferredHeight() { return font_height; } public int getPreferredWidth() { return 240; } protected void sublayout(int maxwidth, int maxheight) { Field f = this.getField(0); this.setPositionChild(f, 0, 0); this.layoutChild(f, maxwidth, maxheight); f = this.getField(1); this.setPositionChild(f, maxw + 20, 0); this.layoutChild(f, maxwidth, maxheight); this.setExtent(maxwidth, font_height); } private class JunkField extends EditField { private boolean firstFocus; public JunkField(String deflt) { super(Field.EDITABLE | Field.FOCUSABLE); this.setText(deflt); this.setFilter(new NumericTextFilter(TextFilter.NUMERIC)); this.firstFocus = false; } protected void onFocus(int direction) { this.firstFocus = true; } protected boolean keyChar(char key, int status, int time) { if (this.firstFocus) { this.setText(""); this.firstFocus = false; } return super.keyChar(key, status, time); } } } }
-
Error when creating custom text field
HI Guyz,
I am getting below error while creating a new custom UDF text field. All the world is facing this problem earlier?
"Houston-COLUMN_UNAVAILABLE: no additional custom attributes of this type cannot be created"
Swati - PÉAN
The problem is finally solved.
Yes, there are several udf to IOM. However, it stores the details in a table of the adf. Cleaning of the custom fields were created.
TRUNCATE TABLE ADF_EXTENSION_COLUMN_USAGE;
DELETE ADF_EXTENSIBLE_TABLE_USAGE;
COMMIT;
-Swati Pandey
-
Format custom text field only when the field is filled
I have created a form that I need to have the format of a text field "model:"& value of text field, then when it is empty so it is just empty.»
I put event.value = "template:" + event.value; "." in the format custom properties of the text field it set to format correctly, but if it had not entered in this field he said always model: so what should I do for it to be only occur when there is something entered in the field.
Change to:
If (event.value) event.value = "template:"+ event.value; ".
-
How to make a text field that starts with "Dear," pulls a name to a different field, then ends with a comma?
If the name of the other field is 'Name', say, you can use this code as the custom code of the field:
var name = this.getField("Name").value;
If (name) event.value = 'Expensive' + name + by ', ';
else event.value = "";
-
iOS text field problem.
I need the user to enter a Word, so I added a simple text field to the stage. However, it behaves strangely on the real device (iPod Touch). Attached are two screenshots that show how the font size increases when the input is activated. Everyone knows about this problem?
Hello
I think that you have specified a textFormat to text. You must add the following
Assuming that this is the format
var txtFormat:TextFormat = new TextFormat();
txtFormat.size = 20;
T1 = new TextField();
T1.defaultTextFormat = txtFormat;
Apply the default text format that we just put in the text that is already in the text field ('g')
Otherwise the default text format apply to * new * text * typed * in the text field!
Without this, the original text in text fields ('g') will use the default value for a
Flash text (Times New Roman 12pt), rather than the defaultTextFormat (Times New Roman 20pt) field.
T1.setTextFormat (T1.defaultTextFormat);
addChild (t1);
This affects any existing text in the text field in the specified format (making it the same as the default value). Now, when the text field is rendered first uses the default format that you set, and when you type also uses this same format, and so the format is no longer able to change.
I hope this helps.
Samia
-
refer to his car in custom text field calc
I have a custom for a text field calculation, but I would like to know if it is possible to set the field itself as a variable without having to refer to the field name. EITHER this.getField ("name") works, but I want to use this same script a number other text fields and do not want to customize each one.
To get a reference to the field to which the script is attached, the field object is the value of event.target, so the code could be simplified as follows:
// Custom Calculate script event.target.readonly = getField("Set 1").value === "Off" ? true : false;
I changed to the analysis with a value of "Off", because the script didn't need to know what is the value of exports from the box. A deselected checkbox will have a value of "Off". This makes the script more generic.
-
Please help me with the custom text field FormCalc
There is someone online has done a very good thing for me - they helped me create a text field that would be of type 'this document has been printed on _' and include some day the pdf was printed on the employer's intranet site.
I had a shortcut in my favorites and would click on it and place it on each new document that I needed on.
Because the computer I was using suddenly fell down, can't get the details of how to set it up again. I have a pdf form that includes the box, but when I open it in LiveCycle, it's just empty.
That's what I saved:
< field h = mm "8,4935" name = "PrintedOn" w = "141,0398 mm" x = "-0,0001 mm" y = "0 mm" xmlns ="http://www.xfa.org/schema/xfa-template/2.5/" > ""
< ui >
< textEdit >
< border hand = 'right' presence = "hidden" >
<? templateDesigner styleId aped0? > < / border >
< margin / >
< / textEdit >
< /UI >
< police size = cast "18pt" = "Tahoma" weight = "bold" >
< filling >
< color value = "221,221,221" / >
< / filling >
< / make >
< para hAlign = "center" vAlign = "middle" / >
< link match = "none" / >
< activity = "prePrint" ref = "$host" >
< script >$ .rawValue = concat ("this document has been printed on:", num2date (date (), DateFmt (1))); < /script >
< / event >
< / field >I don't remember what to do to get this working.
I use this text box "print on" ALL the time, and I need to know what to do to get back to work quickly.
If there is someone who could help me, I could also send you a sample of a form which includes it - so you can see exactly what I mean.
If someone could remember how to program this kind of thing in once again and save it in LiveCycle, then explain how I can put it on another computer so I'd really, REALLY appreciate it.
~ Chris
PS - this one as I had put in place only prints print message per day on the first page. If she could somehow print on EACH page of the PDF file without me having to click and add it to each page individually, it would be better... but let's first!
Hello
The script is here. If you place a new textfield in the Master Page and put the following script in the event of pre-publication of the field:
$ = concat("This document was printed on: ", num2date(date(), DateFmt(1)))
The language is FormCalc.
Please note that you don't need to go to the XML Source for this. Simply select the textfield object and open the Script Editor (in the Windows menu). Drag the bottom of the editor bar so that you can see a few lines, and then set the FormCalc language.
Should work,
Niall
-
Verification of the text field problem and requiring an option in the drop-down field
I have a form with several fields that if the user enters information in one or more of the
fields, I need to check that the drop-down list field is not empty.
I got this to work, but now I find that if the user deletes the text in the text field, the user always receives the error message. Here is the script I use:
If
((form1.page1.ListFilesFolders.rawValue) ! = null & & (form1.page1.windsNtwkAccess.rawValue) == null);
{
xfa.host.setFocus (form1.page1.windsNtwkAccess);
xfa.host.messageBox ("Please make a selection in the field of Windows network."
, 'Need to selection' , 1 , 0);
}
Thank you
MDawn
Makes sense... the field is null when the user deletes the text. You could put a white in these areas as default values and test for this instead of null. Now, when the user empty field, it will be null and will not empty so that the message will not appear.
Make sense?
Paul
-
Board for the dynamic text field problem
I'm generating three text fields using an array of text data. The only text that appears is the content of the last element of the array. I have attached my code. Any ideas why three text fields are not created with the text inside elem table?
Thank you!
-Aaron
These depths are not going to change, so each textfield replaces its predecessor. and then they all overlap because you do not change the ownership of the FLF to your textfields. (and your textformat object is not something useful, yet).
-
Hi, who can help me with this
I've done a few members bij field using insert-> control-> field = 1 domain name
and I did I got the movie the following lines of script
put vacuum in the field 1 = to start with a blank
then I put this line for the random words
put random word (5) of "open zien gaan few minute" in field 1
the problem is that the field is not considered to be a field
and so far there is no display text
TIA
Herman
Assuming that really name you your field "Field 1" then try:
put word at random (5) of "open zien gaan few minute" in the field "Field 1"
-
Getpreferredwidth and getpreferredheight custom text field
I have a customtextfield that I have to get the width of textfields, I tried getpreferredwidth() substitution but I'm stacoverflowmethod, I can understand the reason for the error but I tried getwidth() substitution I get 10 as standard response. I am not able to understand the error.
public class CustTextField extends RichTextField{ private String _text; private FontFamily _fontFamily1; private int _size, _color; private Font _headFont = null; public CustTextField(String _text, int _size,int _color, long _property) { super(_text, _property); FontFamily _fontFamily1; this._color = _color; try{ _fontFamily1 = FontFamily.forName("aerial"); } catch(ClassNotFoundException e) { _fontFamily1 = Font.getDefault().getFontFamily(); } _headFont = _fontFamily1.getFont(Font.PLAIN,_size); super.setFont(_headFont); } public int getPreferredWidth() { // TODO Auto-generated method stub return getPreferredWidth(); } protected void paint(net.rim.device.api.ui.Graphics g) { g.setColor(_color); super.paint(g); } }
A Y
You can use font.getAdvance
-
Rich text field, scroll problems
Hello world
I currently have a problem with the rich text fields. I have a selected rich when custom text field (onFocus), it colors the blue text when not selected (onUnfocus), the text is white.
I have Setup several of my RichTextFields in a VerticalFieldManager so they can be scrolled as a list.
Now scrolling works on the following simulators:
Bold 9000 4.6.0.266
Curve 8520 4.6.1.272
But no scrolling does work on this Simulator:
Bold 9700 5.0.442
What Miss me? I know the o/s changed, but if it should not be backward compatible?
I use Blackberry JDE component Package 4.2.1
Any help would be greatly appreciated.
I found the problem. The super I was calling was super (text, Field.FOCUSABLE), this caused the 9700 Simulator not to focus the richtextfields.
The Builder suitable for call is super (Field.FOCUSABLE), and that fixed the issue.
Now, I have another problem. Suddenly, I added a few images, the background (they are all less than 300 KB) tested on simulators of 9000 and 8520, it worked.
When I test it on the 9700, it says net.rim.device.api.system.Application not found
Hint anyone?
Maybe you are looking for
-
How to remove apple news topics?
I like the new product new Apple iOS. However, it seems difficult to manage themes. I used to read the headlines and other news using other applications. My children have iPads that are related to my account and managed by me. I would use the pro
-
I already followed your advice to remove the file plugins.dat from the .mozilla directory. The plugin has not yet appeared in the list of Add-ons. Anyone have an idea what might happen?
-
Rough panoramic F55. Help, please.
IM planing to implement the F55 in a serious TV series production, but all the tests we did, and we want to use the workflow XAVC, proves the matter to be really rough while panning. Much bigger than Alexa or RED. I have the Firmware 1.0.0 but I need
-
KB2686509 security update will not install 0xf0f4 error code
After downloading Microsoft security update for Windows XP (KB2686509) update will not install - what should I do?
-
I can't connect to MSN, NEED of HELP PLEASE!
I can't connect to MSN, it tells me that I must be upgraded. When I klick 'Yes', then it starts searching for updates but can find no updates. When I try to log on again then it is same thing. When I klick 'No' then it is not log. What should I do? I