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
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No
Accepted Solution

How can i create a border of text box.

[ Edited ]

hello,

i want to create border of text box without using XYEdge or BorderFactory.

means custom TextBox.

 

Provide me simple solution

 

answer plz.

Thanks 

Himanshu

Please use plain text.
Developer
MohammedAziz
Posts: 139
Registered: ‎02-23-2012
My Device: Blackberry bold

Re: How can i create a border of text box.

I think you can do this by paint method.

In paint method you can setBorder method of Graphics class if you are creating a custom textbox.
warm regards
Mohammed Aziz
Please use plain text.
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: How can i create a border of text box.

i ll try this..

Please use plain text.
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: How can i create a border of text box.

[ Edited ]

not creating .....

 

Hepl me now.

Please use plain text.
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold

Re: How can i create a border of text box.

I have created acustom clas to use text box as a text area hope this help

 

package mypackage;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.BitmapField;
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.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;

 

public class CustomTextFieldArea extends VerticalFieldManager{
private Boolean overrideFocusable = null;
private int managerWidth;
private int managerHeight;
private final EditField editField;
private final LabelField lbl;
private final HorizontalFieldManager hfm;
private final VerticalFieldManager vfm;


public CustomTextFieldArea(String label, int width, int height, int maxChars) {
super(Manager.NO_VERTICAL_SCROLL);
managerWidth = width;
managerHeight = height;
lbl = new LabelField();
vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
hfm = new HorizontalFieldManager();

editField = new EditField("", "", maxChars, Field.NON_SPELLCHECKABLE | TextField.NO_COMPLEX_INPUT);

// no length, no label
String trimmedLabel = label.trim();
if (trimmedLabel.length() > 0) {
lbl.setText(trimmedLabel + ":");
hfm.add(lbl);
add(hfm);
}
vfm.add(editField);
add(vfm);
}


public CustomTextFieldArea(String label) {
this(label, Display.getWidth() - 10, 100, EditField.DEFAULT_MAXCHARS);
}


public CustomTextFieldArea(int width, int height, int maxChars) {
this("", width, height, maxChars);
}


public CustomTextFieldArea(int width, int maxChars) {
this("", width, 0, maxChars);
}

public void paint(Graphics g) {
super.paint(g);
int lblHeight = lbl.getHeight();
g.drawRect(0, lblHeight, getWidth(), getHeight() - lblHeight);
}

public void sublayout(int width, int height) {
if (managerWidth == 0) {
managerWidth = width;
}
if (managerHeight == 0) {
managerHeight = height;
}
super.sublayout(managerWidth, managerHeight);
setExtent(managerWidth, managerHeight);
}

public String getText() {
return editField.getText();
}

public void setText(String text) {
editField.setText(text);
}


public void clear() {
setText(null);
}


public void setFocusable(boolean focusable) {
this.overrideFocusable = focusable ? Boolean.TRUE : Boolean.FALSE;
}


public boolean isFocusable() {
if (null == overrideFocusable) {
return super.isFocusable();
}
return overrideFocusable.booleanValue();
}

public void setLable(String string) {
lbl.setText(string);

}

public void setEditable(boolean editable) {
super.setEditable(editable);
editField.setEditable(editable);
}

public void setImage(BitmapField bitmapField) {
hfm.add(bitmapField);
}

public String toString() {
return getText();
}


}

Please use plain text.
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: How can i create a border of text box.

nice code  

but is there any small code for textbox and its border...

 

 

plz .

Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can i create a border of text box.

Please use plain text.
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold

Re: How can i create a border of text box.

I have removed some unused code.....check this

 

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
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.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;

 

public class CustomTextFieldArea extends VerticalFieldManager{
private int managerWidth;
private int managerHeight;
private final EditField editField;
private final LabelField lbl;
private final HorizontalFieldManager hfm;
private final VerticalFieldManager vfm;


public CustomTextFieldArea(String label, int width, int height, int maxChars) {
super(Manager.NO_VERTICAL_SCROLL);
managerWidth = width;
managerHeight = height;
lbl = new LabelField();
vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
hfm = new HorizontalFieldManager();
editField = new EditField("", "", maxChars, Field.NON_SPELLCHECKABLE | TextField.NO_COMPLEX_INPUT);
String trimmedLabel = label.trim();
if (trimmedLabel.length() > 0) {
lbl.setText(trimmedLabel + ":");
hfm.add(lbl);
add(hfm);
}
vfm.add(editField);
add(vfm);
}

public void paint(Graphics g) {
super.paint(g);
int lblHeight = lbl.getHeight();
g.drawRect(0, lblHeight, getWidth(), getHeight() - lblHeight);
}

public void sublayout(int width, int height) {
if (managerWidth == 0) {
managerWidth = width;
}
if (managerHeight == 0) {
managerHeight = height;
}
super.sublayout(managerWidth, managerHeight);
setExtent(managerWidth, managerHeight);
}

public String getText() {
return editField.getText();
}

public void setText(String text) {
editField.setText(text);
}


public void clear() {
setText(null);
}


}

Please use plain text.
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: How can i create a border of text box.

[ Edited ]

Thanks this code is good and gettable by new beginners .

 

Thanks alot peter_strange Sir.

 

Himanshu

Please use plain text.
Contributor
adrianmann1963
Posts: 19
Registered: ‎05-26-2011
My Device: curve

Re: How can i create a border of text box.

Can you not read a manual or search the net for examples !?

Please use plain text.