Tuesday, February 14, 2012

EditField Border

BasicEditField emailField = new BasicEditField("Email Address: ", "", 100, BasicEditField.FILTER_EMAIL)
{
    private int iRectX = getFont().getAdvance(getLabel());
    private int iRectWidth = Display.getWidth() - iRectX - 4;

    public int getPreferredWidth() {
        return Display.getWidth();
    }

    public int getPreferredHeight() {
        return 30;
    }

    public void layout(int width, int height) {
        super.layout(width, getPreferredHeight());
        setExtent(width, getPreferredHeight());
    }
            
    public void paint(Graphics g) {
        g.setColor(0x000000);
        g.drawRect(iRectX, 0, iRectWidth, 16);
        super.paint(g);
    }
};
// ---------------------------------------------
// layout after setExtent (seems to wipe effect of setExtent)
BasicEditField emailField2 = new BasicEditField("Email Address2: ", "", 100, BasicEditField.FILTER_EMAIL)
{
    private int iRectX = getFont().getAdvance(getLabel());
    private int iRectWidth = Display.getWidth() - iRectX - 4;
    public int getPreferredHeight() {
        return 30;
    }

    public void layout(int width, int height) {
        setExtent(width, getPreferredHeight());
        super.layout(width, getPreferredHeight());
    }
            
    public void paint(Graphics g) {
        g.setColor(0x000000);
        g.drawRect(iRectX, 0, iRectWidth, 16);
        super.paint(g);
    }
};

1 comment:

  1. Not working properly.The text is out off lines.
    plz check it.

    ReplyDelete