在文本字段中设置文本光标,Java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13451256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:47:17  来源:igfitidea点击:

set text cursor in text field, Java

javaswingcursorjframetextfield

提问by dtnder

I have two text fields, and text_field2 text_fiel1. when the program is run directly to the text cursor automatically text_field1. I want to ask how can I make the text cursor when the program is run automatically in text_field2 not in text_cursor1???

我有两个文本字段和 text_field2 text_fiel1。程序运行时直接将文本光标自动移到text_field1。我想问一下当程序在text_field2而不是text_cursor1中自动运行时,如何制作文本光标???

回答by vikas devde

requestFocus() method of JTextfield will do. look at this http://www.java2s.com/Code/JavaAPI/javax.swing/JTextFieldrequestFocus.htm

JTextfield 的 requestFocus() 方法就可以了。看看这个http://www.java2s.com/Code/JavaAPI/javax.swing/JTextFieldrequestFocus.htm