Reputation: 21
I'm trying to set the text alignment in a textfield in Codename One. I've already created a style to set the alignment but it doesn't work.
I can set the alignment to the right and left but not in center. I would like to know how to center the text(value) in the textfield.
Does anyone know how to do this?
Thank you in advance.
Upvotes: 2
Views: 858
Reputation: 3411
Center alignment works if you use Textarea instead of Textfield.
TextArea textAreaInput = new TextArea();
and then :
textAreaInput.getAllStyles().setAlignment(TextArea.CENTER);
But, as Shay points out, during editing the text aligns to the left.
Upvotes: 0
Reputation: 896
I dont think that you even need to touch the Style but simply use the setAlignment
method:
TextArea ta = new TextArea() ;
ta.setAlignment(TextArea.CENTER);
Upvotes: 1
Reputation: 1897
check it , it will solve your problem
Form form = new Form(new BoxLayout(BoxLayout.Y_AXIS));
TextField textField = new TextField();
form.addComponent(textField);
textField.setAlignment(TextArea.CENTER);
form.show();
Upvotes: 1