09-06-2012 05:10 AM
hello all...
i try to crreate a custom editfield
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
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.Ui;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
public class BorderEditField extends EditField {
private Border unFocusBorder = BorderFactory.createBitmapBorder( new XYEdges( 12, 12, 12, 12), Bitmap.getBitmapResource("border.png"));
BorderEditField() {
super();
}
BorderEditField(long style) {
super(style);
}
BorderEditField(String label, String initialValue) {
super(label, initialValue);
}
BorderEditField(String label, String initialValue, int maxNumChars, long style) {
super(label, initialValue, maxNumChars, style | Field.USE_ALL_WIDTH);
super.setFont(getTextFont());
setBorder(unFocusBorder);
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.drawText(super.getText(), 0, 0, DrawStyle.HCENTER + DrawStyle.ELLIPSIS + DrawStyle.TRUNCATE_BEGINNING, getWidth() - 12);
}
protected void layout(int width, int height) {
super.layout(width, height);
}
private Font getTextFont() {
FontFamily alphaSerifFamily = null;
try {
alphaSerifFamily = FontFamily.forName("bbalpha serif");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Dialog.alert(e.getMessage());
}
return alphaSerifFamily.getFont(Font.PLAIN, 18, Ui.UNITS_pt);
}
}
when i enter a char that more the field could display it would create like a new line but the text is still on the 1st line
the 2nd line was empty...
how to make the custom editfield not showing the 2nd line? since the 2nd line was an empty text
the text was only on 1st line
Solved! Go to Solution.
09-06-2012 05:18 AM
09-06-2012 05:27 AM
yes i could but i want to paint it as i want, thats why i create another class for it
the problem is like the picture
09-06-2012 05:33 AM
09-06-2012 05:48 AM
Agree with Simon.
In your case change this:
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.drawText(super.getText(), 0, 0, DrawStyle.HCENTER + DrawStyle.ELLIPSIS + DrawStyle.TRUNCATE_BEGINNING, getWidth() - 12);
}
to this:
public void paint(Graphics g) {
g.setColor(Color.BLACK);
super.paint(g)
}
and see if your problem is resolved.
09-06-2012 06:12 AM
09-06-2012 06:19 AM
well i found a way to make it work
protected void layout(int width, int height) {
super.setExtent(width, height);
setExtent( isStyle( USE_ALL_WIDTH ) ? width : getPreferredWidth(), getPreferredHeight() );
}
public void updateScreen() {
invalidate();
}
im adding this to the bordereditfield
but have to invalidate everytime i enter a text.