I want to dispaly some data at the top of the screen and some at the end of the screen,creating two different managers,the issue is after running i cannot see any data on the screen
public NativeScreen() {
super();
LabelField title = new LabelField("Calendar DatePicker",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
hrzManager = new HorizontalFieldManager() {
protected void paintBackground(Graphics graphics) {
graphics.setBackgroundColor(0x0007F5ED);
graphics.clear();
super.paint(graphics);
}
};
hrzManager.add(title);
VerticalFieldManager verticalFieldManagerUpper = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL |
Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH ) ;
verticalFieldManagerUpper.add(hrzManager);
//Add the manager to the screen.
this.add(verticalFieldManagerUpper);
VerticalFieldManager verticalFieldManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL |
Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH ) ;
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT);
ImageButtonField bitmapField = new ImageButtonField(Bitmap.getBitmapResource("pimdemo_jde.png"), Field.FIELD_BOTTOM);
horizontalFieldManager.add(bitmapField);
ImageButtonField bitmapField1 = new ImageButtonField(Bitmap.getBitmapResource("attachmentdemo_jde.png"), Field.FIELD_BOTTOM);
horizontalFieldManager.add(bitmapField1);
//Add the fields to the manager.
verticalFieldManager.add(horizontalFieldManager);
//Add the manager to the screen.
this.add(verticalFieldManager);
Use the set status and set title -
setTitle(field);
setStatus(field);
Related
I have a GridFieldManager whith 3 columns and I want to align their content like this:
|Title left | Title Center | Title Right|
The problem is that I'm using a RichTextField instead of a LabelField because I want the text of each title to grap like this:
|Title left | Title Center | Title Right |
|is wrapped | is wrapped too | also wrapped |
If I use RichTextField instead of LabelField, then, the the alignment is ignored. This is my code:
public class CustomGridFieldextends GridFieldManager {
private int numColumns = 3;
private int margin = 5;
public CustomGridField(String leftText, String centerText, String rightText) {
super(1, 3, GridFieldManager.USE_ALL_WIDTH);
setPadding(0, margin, 0, margin);
int columnWidth = (Display.getWidth() / numColumns);
for (int i = 0; i < numColumns; i++) {
setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
}
// leftmost text
RichTextField leftLabel = new RichTextField(leftText){
protected void paint(Graphics g) {
g.setColor(Color.WHITE);
g.setFont(getFont().derive(Font.BOLD));
super.paint(g);
}
};
leftLabel.setFont(getFont().derive(Font.BOLD));
add(leftLabel, Field.FIELD_LEFT);
// center text
RichTextField centerLabel = new RichTextField(centerText){
protected void paint(Graphics g) {
g.setFont(getFont().derive(Font.BOLD));
g.setColor(Color.WHITE);
super.paint(g);
}
};
centerLabel.setFont(getFont().derive(Font.BOLD));
add(centerLabel, Field.FIELD_HCENTER);
// rightmost text
RichTextField rightLabel = new RichTextField(rightText) {
protected void paint(Graphics g) {
g.setFont(getFont().derive(Font.BOLD));
g.setColor(Color.WHITE);
super.paint(g);
}
};
rightLabel.setFont(getFont().derive(Font.BOLD));
add(rightLabel, Field.FIELD_RIGHT);
}
protected void paintBackground(Graphics g) {
// draw a nice background...
}
}
Found the answer, turns out that I had to use this styles when creating the RichTextFields:
new RichTextField("text on left",RichTextField.TEXT_ALIGN_LEFT);
new RichTextField("text on center",RichTextField.TEXT_ALIGN_HCENTER);
new RichTextField("text on right",RichTextField.TEXT_ALIGN_RIGHT);
Now I'm working on the grapping...
PD: found it here: http://v4ks1n.wordpress.com/2009/04/16/richtextfield-alignment/
I am trying to align images at the bottom of the screen in the format img1 str img2 |img3 ,the issue i am facing is if the str is small the images are getting shifted left ,else the images moves right based on the string length.I want to keep the images always at the right corner ,how to do it ?
VerticalFieldManager test = new VerticalFieldManager();
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(
FIELD_BOTTOM | Manager.USE_ALL_WIDTH) {
public void paint(Graphics graphics) {
graphics.setBackgroundColor(0x316AC5);
graphics.clear();
super.paint(graphics);
}
};
Bitmap fadeBitmap = Bitmap
.getBitmapResource("icon_tz_faded_316AC5_35x39.png");
Bitmap clockBitmap = Bitmap
.getBitmapResource("icon_date_picker_white_316AC5_35x39.png");
Bitmap tzBitmap = Bitmap
.getBitmapResource("icon_tz_white_316AC5_35x39.png");
final ImageButtonField unfocus = new ImageButtonField("",
Field.FOCUSABLE | FIELD_LEFT, "icon_tz_faded_316AC5_35x39.png",
"icon_tz_faded_316AC5_35x39.png", 0xFFFFFF);
final ImageButtonField bitmapField = new ImageButtonField("",
Field.FOCUSABLE | ImageButtonField.FIELD_RIGHT,
"icon_date_picker_white_316AC5_35x39.png",
"icon_date_picker_selected_35x39.png", 0xFFFFFF);
final ImageButtonField bitmapField1 = new ImageButtonField("",
Field.FOCUSABLE | ImageButtonField.FIELD_RIGHT,
"icon_tz_white_316AC5_35x39.png", "icon_tz_selected_35x39.png",
0xFFFFFF);
int margin = ((Display.getWidth() - (fadeBitmap.getWidth()
+ clockBitmap.getWidth() + tzBitmap.getWidth() + timezoneTitle
.getWidth())) / 4);
unfocus.setMargin(0, 3, 0, 0);
timezoneTitle.setMargin(0, 120, 0, 0);
bitmapField1.setMargin(0, 0, 0, 0);
horizontalFieldManager.add(unfocus);
horizontalFieldManager.add(timezoneTitle);
horizontalFieldManager.add(bitmapField);
horizontalFieldManager.add(bitmapField1);
test.add(horizontalFieldManager);
Create another horizontal field and add images to this field, then use setPadding(top,left,bottom,right) to arrange the images in order.
attempting a first Blackberry App.
It will display diary data (eventually).
I'm just trying to get things working bit by bit.
I can't get the buttons to work in the simulator ie I click them and nothing happens.
Any help appreciated.
Code is below (hopefully ok formatted - first post so apologies if not).
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
/**
* A class extending the MainScreen class.
*/
public class MyScreen extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField lastWeek;
ButtonField todayWeek;
ButtonField nextWeek;
LabelField Monday;
LabelField MondayData;
LabelField Tuesday;
LabelField TuesdayData;
LabelField Wednesday;
LabelField WednesdayData;
LabelField Thursday;
LabelField ThursdayData;
LabelField Friday;
LabelField FridayData;
LabelField Satday;
LabelField SaturdayData;
LabelField Sunday;
LabelField SundayData;
public MyScreen(){
LabelField banner = new LabelField("Diary",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField title = new LabelField("Week starting...",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Monday = new LabelField("Monday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField MondayData = new LabelField("MondayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Tuesday = new LabelField("Tuesday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField TuesdayData = new LabelField("TuesdayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Wednesday = new LabelField("Wednesday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField WednesdayData = new LabelField("WednesdayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Thursday = new LabelField("Thursday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField ThursdayData = new LabelField("ThursdayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Friday = new LabelField("Friday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField FridayData = new LabelField("FridayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Saturday = new LabelField("Saturday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField SaturdayData = new LabelField("SaturdayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Sunday = new LabelField("Sunday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField SundayData = new LabelField("Sundaydata",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_HCENTER);
ButtonField lastWeek = new ButtonField("<<", ButtonField.CONSUME_CLICK);
lastWeek.setChangeListener(this);
ButtonField todayWeek = new ButtonField("Today", ButtonField.CONSUME_CLICK);
todayWeek.setChangeListener(this);
ButtonField nextWeek = new ButtonField(">>", ButtonField.CONSUME_CLICK);
nextWeek.setChangeListener(this);
hfm.add(lastWeek);hfm.add(todayWeek);hfm.add(nextWeek);
hfm.setPadding(10, 0, 10, 0);
VerticalFieldManager vfm = new VerticalFieldManager(Field.FIELD_VCENTER);
vfm.add(Monday);
vfm.add(MondayData);
vfm.add(Tuesday);
vfm.add(TuesdayData);
vfm.add(Wednesday);
vfm.add(WednesdayData);
vfm.add(Thursday);
vfm.add(ThursdayData);
vfm.add(Friday);
vfm.add(FridayData);
vfm.add(Saturday);
vfm.add(SaturdayData);
vfm.add(Sunday);
vfm.add(SundayData);
add(vfm);
add(new SeparatorField());
setTitle(title);
setBanner(banner);
setStatus(hfm);
}
public void fieldChanged(Field field, int context) {
if (field == lastWeek) {
lastTextFields();
}
else if (field == todayWeek) {
todayTextFields();
}
else if (field == nextWeek) {
nextTextFields();
}
}
private void lastTextFields() {
Monday.setText("Monday-old");
MondayData.setText("MondayData-old");
}
public void todayTextFields() {
//Monday.setText("Monday");
// MondayData.setText("MondayData");
Dialog.inform("Today pressed");
}
private void nextTextFields() {
Monday.setText("Monday-new");
MondayData.setText("MondayData-new");
}
}
Since you are running your application on 8520 device simulator that doesn't have touch screen, clicking on the buttons will get you nowhere. There are several options available:
Navigate to desired button by using one of the following methods:
Use the keyboard arrow keys to navigate. Press Enter to "click" on it.
Use your mouse's scroll wheel to navigate and then left click to "click".
Press F12 to turn "trackball mode" on and use your mouse navigate. Then either press Enter or right click when the desired button is selected.
Also check this Use the trackball and other Simulating BlackBerry device interaction manuals.
Alternatively, you can compile your application with JRE 6.0 or higher and pick a use a device simulator that supports touchscreen (9800 Torch, 9930 Bold and etc...).
EDIT
You are initiating local LabelFields and ButtonFields instead of the class' member variable. All class member variable remained uninitialized (e.g. equal null). You should remove the redundant local variable definitions.
Update all your LabelFields and ButtonFields in the following way:
LabelField banner = new LabelField("Diary", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
ButtonField lastWeek = new ButtonField("<<", ButtonField.CONSUME_CLICK);
I want my button to be at the right side and bottom side. How it is possible? Please help me. My code below only displays the button on the right side but not bottom.
ButtonField b = new ButtonField("button", Field.FIELD_RIGHT | FIELD_BOTTOM);
VerticalFieldManager vf = new VerticalFieldManager(Field.USE_ALL_WIDTH);
vf.add(b);
add(vf);
By default, a VerticalFieldManager will only use the smallest amount of vertical space necessary to display all of its children. So, your button is displaying at the bottom of the manager, but the manager is only as tall as your button. Also, a VerticalFieldManager is intended for top-down display. Try something like this:
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_BOTTOM);
ButtonField b = new ButtonField("Button", Field.FIELD_RIGHT);
vfm.add(b);
hfm.add(vfm);
add(hfm);
thanks to all. but i got my answer.
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH) {
public int getPreferredWidth() {
return Display.getWidth();
}
public int getPreferredHeight() {
return Display.getHeight();
}
protected void sublayout(int maxWidth, int maxHeight) {
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
super.sublayout(displayWidth, displayHeight);
setExtent( Math.min( Display.getWidth(), getPreferredWidth() ),
Math.min( Display.getHeight(), getPreferredHeight() ) );
}
};
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_RIGHT);
ButtonField b = new ButtonField("Button", Field.FIELD_RIGHT);
vfm.add(b);
hfm.add(vfm);
add(vfm);
It's perfect work to me.
This is my screen:
final class GeneralExpenseViewScreen extends MainScreen {
public GeneralExpenseViewScreen() {
super();
LabelField title = new LabelField("TeamMate TEC | Expenses",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
Background bg = BackgroundFactory.createSolidBackground(0xBDBDDB);
setBackground(bg);
HorizontalFieldManager headerAreaManager = new HorizontalFieldManager();
HorizontalFieldManager filterAreaManager = new HorizontalFieldManager();
HorizontalFieldManager expenseListAreaManager = new HorizontalFieldManager();
HorizontalFieldManager totalAreaManager = new HorizontalFieldManager();
HorizontalFieldManager addNewAreaManager = new HorizontalFieldManager();
add(headerAreaManager);
add(filterAreaManager);
add(expenseListAreaManager);
add(totalAreaManager);
add(addNewAreaManager);
/**Begin form layouts**/
Bitmap headerImage = Bitmap.getBitmapResource("sergioheader.png");
BitmapField header = new BitmapField(headerImage);
headerAreaManager.add(header);
}
public boolean onClose() {
Dialog.alert("AH!");
System.exit(0);
return true;
}
}
Notice that I'm calling setBackground directly to the class but it's not working how I think it would work.
How can I set a background color to my application form?
Thanks.
I've used this code with success:
protected void paint(Graphics graphics) {
graphics.setBackgroundColor(0xBDBDDB);
graphics.clear();
super.paint(graphics);
}
Depending on the version you're developing for, you could use the following
getMainManager().setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
to set the screen managers background color.