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: 122
Registered: ‎11-12-2010
My Device: Dev Alpha
My Carrier: N/A
Accepted Solution

Label, Edit Field and button on one row problem

Hi All

 

I've been pulling my hair out on this and could really do with some guidence. I am trying to put a label, an edit field and a bitmapfield button on the same row but for the life of me I can't get it to work that way round. If I put the button field before the textbox it works.

 

        // TEST 3 CONTROLS ON A ROW
        
        final Bitmap imgCalc = Bitmap.getBitmapResource("bgCalc.png");
        
        LabelField lb = new LabelField("0.00");
        EditField ef = new EditField();
        BitmapField  bf = new BitmapField(imgCalc, BitmapField.FOCUSABLE){
        	protected void paint(Graphics g) {
        		// Draw text on button image
        		super.paint(g);
        		g.setColor(Color.WHITE);
                int x = (40 - Font.getDefault().getAdvance("Go"))/2;
                int y = (imgCalc.getHeight() - Font.getDefault().getHeight())/2;
        		g.drawText("Go", x, y);
        	}
        	
    		public int getPreferredWidth(){ 
    			return 40; 
    		}        	
        };
        
        HorizontalFieldManager row0 = new HorizontalFieldManager();
        
        row0.add(lb);
        row0.add(ef);
        row0.add(bf);

 

Excuse the code but this is test code to try and get it working. As mentioned above, if I add the controls Label, Edit, Bitmap it only shows the label and edit field. If I swap the text field and bitmap field around so that the text field is last, it works.

 

What am I doing wrong?

 

Thanks for looking

 

Paul

Contributor
Posts: 43
Registered: ‎11-30-2011
My Device: Dev Alpha, 8520
My Carrier: Vodafone

Re: Label, Edit Field and button on one row problem

[ Edited ]

EditField always takes up all of the width available to it.

 

You need to override its layout(width, height) and pass values lesser than width to leave some space for the BitmapField. Something like

 

protected void layout(int width, int height)
	{
		super.layout(width * 60 / 100, height);
		// sets width of this field to 60% of the total available width
	}

 would do.



I've got 99 problems and eclipse is all of them


Twitter

Developer
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha
My Carrier: N/A

Re: Label, Edit Field and button on one row problem

Thank you newton53 Smiley Happy

PS - love your signature line - made me laugh.