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
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL
Accepted Solution

EditField Layout

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

 

 

 

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

Re: EditField Layout

why don't you use setBorder on a standard editfield?
----------------------------------------------------------
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
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: EditField Layout

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

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

Re: EditField Layout

if you want to have custom painting you should override field, not editfield.
editfield is a VERY complex class with loads of processing, you cannot modify it heavily (overriding paint is quite some) and expect it 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.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: EditField Layout

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.

Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: EditField Layout

so its not possible to make 1 line ? have to create a new class for it?

@peter
using super.paint(g) is still display as normal edit field
Highlighted
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: EditField Layout

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.