大家好我不熟悉黑莓,我想要一个文本字段滚动它的文本,即水平地大于首选宽度,也能够在文本绘制区域外显示标签(例如在左侧)。请帮我。
答案 0 :(得分:4)
这可以通过组合非滚动和滚动HorizontalFieldManagers来实现。
试试这段代码:
class Scr extends MainScreen {
public Scr() {
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
editHolder.add(new TextField(TextField.NO_NEWLINE));
fieldHolder.add(editHolder);
add(fieldHolder);
}
}
设置默认文本代码:
class Scr extends MainScreen {
public Scr() {
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField(TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
// set some text then
String text = "Lorem ipsum dolor sit amet, consectetuer"+
" adipiscing elit, sed diam nonummy nibh euismod tincidunt"+
" ut laoreet dolore magna aliquam erat volutpat.";
textField.setText(text);
}
}
基本适用于4.6 / 4.7的东西:
class Scr extends MainScreen {
public Scr() {
String text = "Lorem ipsum dolor sit amet, consectetuer"+
" adipiscing elit, sed diam nonummy nibh euismod tincidunt"+
" ut laoreet dolore magna aliquam erat volutpat.";
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField("",text,1024,TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
}
}
Border border = BorderFactory.createSimpleBorder(new XYEdges(4,4,4,4));
fieldHolder.setBorder(border);
class SizedHFM extends HorizontalFieldManager {
int mWidth = 0;
public SizedHFM(int width) {
super(NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
mWidth = width;
}
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(mWidth, maxHeight);
setExtent(mWidth, getPreferredHeight());
}
}
使用样本:
class Scr extends MainScreen {
public Scr() {
String text = "Lorem ipsum dolor sit amet, consectetuer"
+ " adipiscing elit, sed diam nonummy nibh euismod tincidunt"
+ " ut laoreet dolore magna aliquam erat volutpat.";
SizedHFM fieldHolder = new SizedHFM(200);
Border border = BorderFactory
.createSimpleBorder(new XYEdges(4, 4, 4, 4));
fieldHolder.setBorder(border);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField("", text, 1024,
TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
}
}