03-31-2011 11:02 AM
I build an EditField with the following method :
BasicEditField searchField = new BasicEditField("", "", 30, TextField.NO_NEWLINE); searchField.setBorder(VISUAL_STATE_NORMAL, BorderFactory.createRoundedBorder(new XYEdges(7,7,7,7)));
The problem is that the cursor is displayed over the border.
How can I do to specify the cursor to be centered between the upper and lower border and takes a given padding from left and right ?
Thanks in advance.
03-31-2011 11:20 AM
I've seen a few border problems with (Basic)EditField reported here on the forum. Generally, the workaround I suggest is this: have your field in a separate (dedicated) manager and setBorder on the manager rather than the field. I have a feeling that BasicEditField implementation has a bug displaying the cursor - apparently they forgot to take Border into account while calculating its position.
By the way, padding for BasicEditField is also broken, so, again, that functionality is better delegated to a manager as well. And, while you are at it, check the correctness of setBackground.
03-31-2011 11:58 AM
Something like this ?
HorizontalFieldManager searchManager = new HorizontalFieldManager(Field.FIELD_HCENTER | Field.USE_ALL_WIDTH); BasicEditField searchField = new BasicEditField("", "", 30, Field.FIELD_HCENTER | TextField.NO_NEWLINE); searchManager.setBorder(VISUAL_STATE_NORMAL, BorderFactory.createRoundedBorder(new XYEdges(5,5,5,5))); searchManager.setMargin(10, 10, 10, 10); searchManager.setPadding(5,5,5,5); searchManager.add(searchField);
But the behaviour is the same : the cursor is still displayed over the border.
03-31-2011 01:13 PM
Hmmm, that's weird...
You can take another step and layout the field and paint the border manually. If you take a look at the code below, you'll see an example of how it can be done:
Pay attention at layoutChild and setPositionChild calls - they should give you ideas on how to manage the screen on a lower level.
In fact, take some time to read the whole article - it seems that you might really benefit from it. The border there is rectangular with settable thickness and different top, right, bottom and left border shades, but you may throw out all those drawLine calls and replace them with one drawRoundRect.