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
New Developer
Posts: 11
Registered: ‎12-19-2008
My Device: Not Specified
Accepted Solution

How to Left Justify DateField ?

[ Edited ]

Hello all,

 

 

I have very basic question with respect to alignment about DateField.

 

 

By default, the DateField will have a label on the extreme extreme leftside and value on extreme rightside of the sceen.

 

Is it possible to achieve the DateField as shown below ? If yes, how ?

 

Date: (Label)

31st Dec, 2008 12:00 (Value)

 

 

Thanks in advance,

--Premal

Message Edited by Premal on 12-31-2008 04:22 AM
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: How to Left Justify DateField ?

Unfortunately - it is not possible with DateField class.

 

The value is always right aligned.

Developer
Developer
Posts: 319
Registered: ‎07-20-2008
My Device: Not Specified

Re: How to Left Justify DateField ?

You could try using 2 fields.  A LabelField for "Date:" and a DateField date field with a null label.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: How to Left Justify DateField ?

2 gtj

 

It does not work.

 

He will get a left-aligned label. And right aligned date field without prompt on the next line.

Developer
Posts: 46
Registered: ‎07-12-2008
My Device: Not Specified

Re: How to Left Justify DateField ?

Try this:

DateField field = new DateField("A Date: ", 0, new SimpleDateFormat(DateFormat.DATETIME_DEFAULT), Field.FIELD_LEFT | DrawStyle.LEFT | Field.FOCUSABLE);

 

This creates a field that looks like this:

A Date: Jan 1, 1970 12:00 AM

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: How to Left Justify DateField ?

[ Edited ]

Try this code. Just create simple project with two java classes (see below)

It works.

 

Application class

package com.polygon.app;

import com.polygon.app.view.MyScreen;
import net.rim.device.api.ui.UiApplication;

public class Application extends UiApplication{

public static void main(String[] args) {
(new Application()).enterEventDispatcher();
}

public Application() {
this.pushScreen(new MyScreen());
}
}

 

MyScreen class

package com.polygon.app.view;

import net.rim.device.api.i18n.DateFormat;
import net.rim.device.api.i18n.SimpleDateFormat;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.DateField;
import net.rim.device.api.ui.component.LabelField;

public class MyScreen extends MainScreen {

public MyScreen() {
super();
addScreenItems();
}

public void addScreenItems() {
this.add(new LabelField("Date"));
DateField field = new DateField("", 0, new SimpleDateFormat(DateFormat.DATETIME_DEFAULT), Field.FIELD_LEFT | DrawStyle.LEFT | Field.FOCUSABLE);
this.add(field);
}
}

 

 

 

Message Edited by tbilisoft on 31-12-2008 06:48 PM
New Developer
Posts: 11
Registered: ‎12-19-2008
My Device: Not Specified

Re: How to Left Justify DateField ?

Hello Guys,

 

First of all, many thanks to tbilisoft, gtj and ryandevore.

 

Yes, this is the perfect solution for my requirement.

 

Once again, thanks a lot to all of you for your time and help.

 

Happy Premal Smiley Happy

 

New Contributor
Posts: 3
Registered: ‎02-18-2011
My Device: Not Specified

Re: How to Left Justify DateField ?

thank you ryandevore.this is wat exactly i want

chamu