如何在BlackBerry应用程序上显示文本框?

时间:2010-09-02 13:42:07

标签: blackberry textbox

alt text

如何添加文本框以便用户可以在表单中输入数值?我需要文本框控件的边框始终可见。

感谢。

1 个答案:

答案 0 :(得分:3)

您应该实现自己的类,继承自TextBox并覆盖 void paint(Graphics g)方法。

Smth,就像那样,抱歉我用手机写道:

public void paint(Graphics g)
{       
    // set color
    g.setColor(0x555555);
    // draw 100*100 rectangle 
    g.drawRect(0, 0, 100, 100);
    // dont forget to invoke 
    super.paint(g);
}

如果你不想使用覆盖, 在OS 4.6+中,您可以使用Border and BorderFactory类(在“所有类”列表中搜索)。

// Each integer represents the amount of space between the box and border
// The four parameters of an XYEdge object represents each edge, 
XYEdges thickPadding = new XYEdges(10, 10, 10, 10);

// Sample text field with a thick and solid rounded border
// and single solid colour background.
RichTextField simpleField = new RichTextField("Solid rounded border, solid background");

// Create border and background objects 
Border roundedBorder = BorderFactory.createRoundedBorder(thickPadding, Border.STYLE_SOLID);

// Set the objects for use
simpleField.setBorder(roundedBorder);

// Add the field to the screen
 add(simpleField);