简体   繁体   English

将 cursor 设置为 JTextfield

[英]setting cursor to JTextfield

im trying to get the cursor to move to a textfield when a specific key is pressed like when you press tab.我试图让 cursor 在按下特定键时移动到文本字段,就像按下制表符时一样。 im trying to do this instead of just using tab because i want to implement other actions at the same time, how do i do this?我试图这样做而不是只使用选项卡,因为我想同时执行其他操作,我该怎么做?

here is the key event for keypressed so far这是到目前为止 keypressed 的关键事件

Fname.addKeyListener(new KeyListener(){

        @Override
        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub
            if(e.getKeyCode() == KeyEvent.VK_TAB){
                Sname.setFocusable(true);
                Sname.getFocusAccelerator();

                if(Sname.hasFocus()){
                    Sname.setText("");
                }
            }   
            //System.out.print(e + "keyRelease: ");
        }

any help would be greatly appreciated thank you for your time任何帮助将不胜感激谢谢您的时间

i want to implement other actions at the same time我想同时执行其他操作

Don't use a KeyListener.不要使用 KeyListener。 Swing was designed to use Key Bindings. Swing 旨在使用键绑定。

See Key Bindings for more information and a link to the Swing tutorial on the same topic.有关更多信息,请参阅键绑定以及指向同一主题的 Swing 教程的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM