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: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

How to set the position within the datefield

I am using the datefield,and i am specifying the width of the component,and the datefield goes to the extreme right and how to get it in the center of the specified area(in the dark vilot).

 

this is image link

 

 

Regards

 

Rakesh Shankar.P

Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: How to set the position within the datefield

Hi,

 

I wasn't able to see image inside Chrome.

 

Unfortunately I don't know any legal setters for it. So you can imitate user's input by moveFocus or TrackwheelEvent injections.

 

Thanks,

Eugen

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: How to set the position within the datefield

Use a DrawStyle parameter in the style field.

 

i.e. DateField.TIME | DrawStyle.LEFT

Developer
Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

Re: How to set the position within the datefield

Yes,it worked and other problem that i noticed is that focus on DateField,initially when the form loads,i cannot see the date field,when the focus shifts to it ,it visible,it is visble after that.I dont know why ,it does not get displayed initally.Due to overriding methods,there may be problem is it so?

 

 

Any ideas

 

 

Regards

RakeshShankar.p

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to set the position within the datefield

I suspect there is a bug in your code where you are trying to manipulate the position of the DateField.

 

I think the only way for you to find this is to unravel your logic until you get back to  situation where the DateField is always displayed, then slowly add in your positioning or management logic.

 

Also, try adding a different Field at that position (e.g. a BasicEditField and see if the problem is specific to the DateField.

Highlighted
Developer
Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

Re: How to set the position within the datefield

Hi Peter,I found where pblm is,i couldnt figure out why.I need your help on this

 

this is the code

 

import net.rim.device.api.i18n.SimpleDateFormat;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
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.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.DateField;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



/**
 *
 * @author rakesh_2
 */
public class DatePicker extends Manager implements FieldChangeListener
{
    int compwidth;
    int compht;
    Button ld,ld1;
    int len;
    Font fn;
    DateField df;
    int clr=Color.ORANGE;
    int fclr=Color.GREEN;
    int fclron=Color.ANTIQUEWHITE;
    int val;
    DatePicker()
    {
        
        super(Manager.NO_HORIZONTAL_SCROLL);
        fn=this.getFont().derive(Font.PLAIN|Font.BOLD, 16);
        compwidth=Display.getWidth()/2;
        //compht=Display.getHeight()/4;
        val=Display.getWidth();
        clr=Color.BLUE;
                
        if(val<=300)
        {
             fn=this.getFont().derive(Font.PLAIN|Font.BOLD, 17);
        }
        else if(val>=320&&val<=360)
        {
             fn=this.getFont().derive(Font.PLAIN|Font.BOLD, 22);
        }
        else if(val>360)
        {
            fn=this.getFont().derive(Font.PLAIN|Font.BOLD, 28);
        }
       
        long test=System.currentTimeMillis();
        SimpleDateFormat SDF = new SimpleDateFormat("dd/MM/yyyy");
        df=new DateField("",System.currentTimeMillis(),SDF,DateField.DATE|DrawStyle.LEFT)
       {
           
          protected void paint(Graphics g)
            {
                g.setColor(fclr);
                g.setBackgroundColor(clr);
                super.paint(g);
            } 
         
            protected void drawFocus(Graphics g,boolean on)
            {
                if(on)
                {
                    g.setColor(fclron);
                    super.paint(g);
                    
                }
               
            }
                    
                    
           public void paintBackground(Graphics g)
            {   
                g.setColor(fclr);
                g.setBackgroundColor(clr);
                g.clear();
            }
           /*public int  getPreferredWidth()
            {
                return val;
            }
            public void layout(int wid,int ht)
            {
                this.setExtent(this.getPreferredWidth(),40);
            }*/
        };
        
        df.setFont(fn);
       
        
        len=Display.getWidth()*2/4;
        ld=new Button(Bitmap.getBitmapResource("prev-passive.png"),Bitmap.getBitmapResource("prev.png"),Field.FIELD_HCENTER);        ;
        ld1=new Button(Bitmap.getBitmapResource("next-passive.png"),Bitmap.getBitmapResource("next.png"),Field.FIELD_HCENTER);
        compht=ld.GetButtonht()*2;
        ld.setChangeListener(this); 
        ld1.setChangeListener(this);
        
        this.add(ld);
        this.add(df);
        //this.add(new LabelField("rakesh"));
        this.add(ld1);
       
        
    }

    protected void sublayout(int arg0, int arg1)
    {
        int x=10,y=10;
        int n=this.getFieldCount();
        for(int i=0;i<n;i++)
        {
            Field ff=this.getField(i);
            if(ff instanceof Button)
            {
                this.setPositionChild(ff, x, y);
                this.layoutChild(ff, Display.getWidth() ,Display.getHeight()/4);
                x=x+20;
            }
            if(ff instanceof DateField)
            {
                this.setPositionChild(ff, Display.getWidth()/3, y);
                this.layoutChild(ff, Display.getWidth() ,Display.getHeight()/4);
                x=Display.getWidth()-ld.GetButtonwid()-10;
               
            }
            if(ff instanceof spacefield)
            {
                this.setPositionChild(ff, x+10,y+10);
                this.layoutChild(ff, Display.getWidth() ,Display.getHeight()/4);
            }
             
        }
        this.setExtent(Display.getWidth(),Display.getHeight()/2);
    }
    
  /*  public void paintBackground(Graphics g)
    {
        
        g.setBackgroundColor(Color.BLUEVIOLET);
        g.clear();
    }*/
    public void paint(Graphics g)
    {
        g.setColor(Color.ORANGE);
        g.fillRoundRect(0, 0, Display.getWidth(),compht,15,15);
        g.setColor(Color.RED);
        super.paint(g);
        
    }

    public void fieldChanged(Field arg0, int arg1)
    {
        if(arg0==ld)
        {
             df.setDate(df.getDate()-86400000);
           
        }
         if(arg0==ld1)
        {
           df.setDate(df.getDate()+86400000);
           
        }
    }

    
}

 

 

and i found that the pblm is in DateField methods ,that i override.So i presently commented the codes (i.e) prefferedwidth and layout methods.On Commenting it,it works fine

 

 

Regards

Rakesh Shankar.P