Я не могу выровнять текст на экране BlackBerry. Я пытался использовать LabelField или RichTextField, но текст не выравнивается так, как я хочу. Он выровнен по горизонтали и скрыт на экране. Я хочу, чтобы текст переносился на следующую строку, когда он попадает в конец экрана по горизонтали, а не скрывается.
Вот мой код -
import net.rim.device.api.ui.Color;
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.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
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;
public class DetailBloodBank extends MainScreen
{
String resultData = "", location = "", phoneNumber = "";
LabelField bloodBankName, locationLabel, phoneNumLabel;
String bloodBank = "";
LabelField locationDetail, phoneNumDetail;
public DetailBloodBank(String data) {
super(NO_VERTICAL_SCROLL);
int height = Display.getHeight();
int widhth = Display.getWidth();
//SizedVFM horizontalFieldManager = new SizedVFM(widhth,height);
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.NO_VERTICAL_SCROLL)
{
protected void paint(Graphics g) {
g.setBackgroundColor(Color.BLACK);
g.clear();
super.paint(g);
}
};
//setBanner(horizontalFieldManager);
resultData = data;
System.out.println(resultData);
bloodBankName = new LabelField(resultData)
{
public void paint(Graphics g) {
g.setColor(Color.WHITE);
super.paint(g);
}
};
Font font = Font.getDefault().derive(Font.BOLD, 8, Ui.UNITS_pt);
bloodBankName.setFont(font);
locationLabel = new LabelField("Location")
{
public void paint(Graphics g) {
g.setColor(Color.WHITE);
super.paint(g);
}
};
Font font2 = Font.getDefault().derive(Font.BOLD, 8, Ui.UNITS_pt);
locationLabel.setFont(font2);
phoneNumLabel = new LabelField("Phone Number")
{
public void paint(Graphics g) {
g.setColor(Color.WHITE);
super.paint(g);
}
};
Font font3 = Font.getDefault().derive(Font.BOLD, 8, Ui.UNITS_pt);
phoneNumLabel.setFont(font3);
DBHelpers dbh = new DBHelpers();
dbh.retrieveDetails(resultData);
location = dbh.getLocation();
phoneNumber = dbh.getPhoneNumber();
dbh.getConnectionClose();
phoneNumDetail = new LabelField(phoneNumber)
{
public void paint(Graphics g) {
g.setColor(Color.WHITE);
super.paint(g);
}
};
Font font4 = Font.getDefault().derive(Font.PLAIN, 6, Ui.UNITS_pt);
phoneNumDetail.setFont(font4);
locationDetail = new LabelField(location)
{
public void paint(Graphics g) {
g.setColor(Color.WHITE);
super.paint(g);
}
};
Font font5 = Font.getDefault().derive(Font.PLAIN, 6, Ui.UNITS_pt);
locationDetail.setFont(font5);
final SeparatorField sepfield2 = new SeparatorField(SeparatorField.LINE_HORIZONTAL | Field.USE_ALL_WIDTH)
{
protected void paint(Graphics g) {
g.setBackgroundColor(Color.WHITE);
g.clear();
super.paint(g);
}
protected void layout(int maxWidth, int maxHeight) {
int width = Display.getWidth();
int height = 25; //height of the manager
super.layout(1250, 15);
}
};
final VerticalFieldManager verticalFieldManager = new VerticalFieldManager(NO_HORIZONTAL_SCROLL);
verticalFieldManager.add(locationLabel);
verticalFieldManager.add(locationDetail);
final VerticalFieldManager verticalFieldManager2 = new VerticalFieldManager(NO_HORIZONTAL_SCROLL);
verticalFieldManager2.add(phoneNumLabel);
verticalFieldManager2.add(phoneNumDetail);
VerticalFieldManager routeManager2 = new VerticalFieldManager()
{
protected void sublayout(int width, int height) {
layoutChild(bloodBankName, getPreferredWidth(), getPreferredHeight());
layoutChild(sepfield2, getPreferredWidth(), getPreferredHeight());
layoutChild(verticalFieldManager, getPreferredWidth(), getPreferredHeight());
layoutChild(verticalFieldManager2, getPreferredWidth(), getPreferredHeight());
setPositionChild(bloodBankName, 5, 15);
setPositionChild(sepfield2, 0, 35);
setPositionChild(verticalFieldManager, 0, 72);
int y = verticalFieldManager.getHeight();
System.out.println(y);
setPositionChild(verticalFieldManager2, 0, y + 90);
super.setExtent(width, height);
}
};
routeManager2.add(bloodBankName);
routeManager2.add(sepfield2);
routeManager2.add(verticalFieldManager);
routeManager2.add(verticalFieldManager2);
horizontalFieldManager.add(routeManager2);
add(horizontalFieldManager);
}
}