开发者

setting cursor to JTextfield

开发者 https://www.devze.com 2023-03-27 07:18 出处:网络
im trying to get the cursor to move to a textfield when a specific key is pressed like when you press tab. im trying to do this instead of just using tab because i want to implement other actions at t

im trying to get the cursor to move to a textfield when a specific key is pressed like when you press tab. 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

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. Swing was designed to use Key Bindings.

See Key Bindings for more information and a link to the Swing tutorial on the same topic.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号