0
下面的类是一个文本框字段。这可以修改,以便当文本框填充文本和用户保持键入文本然后滚动?现在发生的事情是,一旦文本框被填充文本,任何后续输入的文本都不会被显示。自定义编辑字段不显示所有键入的文本
感谢
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.EditField;
public class CustomEditField extends EditField {
// private members of the CustomEditField class
private Font defaultFont;
// used to get the default font
private String text;
// used to specify the default width of the table cells
// constructor calls the super class constructor
public CustomEditField(String label, String initialValue, int maxNumChars,
long style) {
super(label, initialValue, maxNumChars, style);
}
// overrides the default getPreferredWidth functionality to return a fixed
// width
public int getPreferredWidth() {
defaultFont = Font.getDefault();
text = "0000000000";
return defaultFont.getAdvance(text);
}
// overrides the default layout functionality to set the width of the table
// cell
protected void layout(int width, int height) {
width = getPreferredWidth();
height = super.getPreferredHeight();
super.layout(width, height);
// uses the super class' layout functionality
// after the width and the height are set
super.setExtent(width, height);
// uses the super class' setExtent functionality
// after the width and the height are set
}
public void paint(Graphics graphics){
graphics.setBackgroundColor(Color.LIGHTBLUE);
super.paint(graphics);
}
}
我不说这是不可能的,但是我相信,有没有简单的方法,因为你将需要覆盖'油漆(图形图像)'行为一起选择与跟踪领域内的插入位置。我还隐约想起有人通过在启用滚动的情况下在'HorizontalFieldManager'内包装'EditField'实现了这一点,但是该解决方案也有点臭。我的建议 - 如果可以的话避免这种情况。 – 2011-03-20 00:04:27
只是一个想法(未测试) - 可能使用嵌入式浏览器字段将允许得到你想要的? – 2011-03-20 00:06:51
对我而言,这似乎很奇怪,因为用户在文本框中键入的文本多于文本框的容量是标准行为,所以这并未实现。 – 2011-03-31 16:09:09