jtextfield 默认光标位置 [英] jtextfield default cursor position
本文介绍了jtextfield 默认光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 JTextField
和文本字段的代码.我正在尝试制作一个与记事本一样大的文本字段,但光标总是出现在中间.我想放在文本字段的开头.
I'm working with JTextField
and the code for the text field. I'm trying to make a textfield as big as the notepad but the cursor always appears in the middle. I want to put in the starting of the textfield.
tf=new JTextField(50);
tf.setCaretPosition(0);
f.setLayout(new BorderLayout());
f.add(tf,BorderLayout.CENTER);
推荐答案
尝试设置文本对齐方式:
Try setting the text alignment:
JTextField textfield = new JTextField("Initial Text");
// Left-justify the text
textfield.setHorizontalAlignment(JTextField.LEFT);
// Center the text
textfield.setHorizontalAlignment(JTextField.CENTER);
// Right-justify the text
textfield.setHorizontalAlignment(JTextField.RIGHT);
这篇关于jtextfield 默认光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文