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
Highlighted
New Developer
Posts: 9
Registered: ‎05-05-2009
My Device: Not Specified
Accepted Solution

The mystery of the missing cursor and the custom Field

Hi  there I hope someone out there can help me with this problem.  I reused a piece of code that I found in the forums called JustifiedEditField.

 

It does just what I wanted but has a little feature/bug. I does not show the cursor when I deleted al of the content in the field. This is very user annoying because the user can’t see where he is when there a more fields in the layout.

 

I searched the knowledge base, the forums and I examined the API but I cannot get the cursor to show. I tried a BB 8310 with os 4.5.0.37 and the simulator 8300. Noting I do shows the cursor in the custom JustifiedEditField.

 

 If I use a out of the box BasicEditField it works fine.

import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;

class StartScreen extends MainScreen {

StartScreen() {

this.setTitle("LayoutTest");
HorizontalFieldManager hfm = new HorizontalFieldManager();
JustifiedEditField jef = new JustifiedEditField("test","12345",10,
BasicEditField.FILTER_INTEGER|BasicEditField.EDITABLE|
BasicEditField.FOCUSABLE);

hfm.add(jef);
this.add(hfm);
}
}

 

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;

public class JustifiedEditField extends HorizontalFieldManager implements FieldChangeListener {

LabelField lf;
EditField ef;
int dw = Display.getWidth(); // signing
int rightMargin;

public JustifiedEditField(String label, String value, int maxChars, long style) {
super(USE_ALL_WIDTH);
ef = new EditField(null, value, maxChars, style) {

protected void onDisplay() {
update(0);
}

protected void update(int d) {
super.update(d);
int efw = getFont().getAdvance(super.getText());
setPosition(dw - efw - rightMargin, 0);
}
};
lf = new LabelField(label,LabelField.NON_FOCUSABLE);
add(lf);
add(ef);
ef.setChangeListener(changelister);
}

FieldChangeListener changelister = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
invalidate();
}
};

public LabelField getLabelField() {
return lf;
}

public EditField getEditField() {
return ef;
}

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

public void setText(String value) {
ef.setText(value);
invalidate();
}

public void setChangeListener(FieldChangeListener changer ){
ef.setChangeListener(changer);
}

public void setRightMargin(int m) {
rightMargin = m;
}

public int getRightMargin() {
return rightMargin;
}

public void fieldChanged(Field field, int context) {
invalidate();
}
}

 

Any help would be greatly appreciated.
Wil.
 

 

 

New Developer
Posts: 9
Registered: ‎05-05-2009
My Device: Not Specified

Re: The mystery of the missing cursor and the custom Field

I found the problem. The field/manager was so wide that the cursor was not visible when the field was empty. 

By adding a four pixel offset in the  setPosition(dw - efw - rightMargin-4, 0); call in the constructor fixed it.

Regards,
Wil.