Allowing the “Enter” key to press the submit button, as opposed to only using MouseClick

前端 未结 7 1132
清歌不尽
清歌不尽 2020-11-27 04:23

I\'m learning Swing class now and everything about it. I\'ve got this toy program I\'ve been putting together that prompts for a name and then presents a JOptionPane with th

相关标签:
7条回答
  • 2020-11-27 05:09
    textField_in = new JTextField();
    textField_in.addKeyListener(new KeyAdapter() {
    
        @Override
        public void keyPressed(KeyEvent arg0) {
            System.out.println(arg0.getExtendedKeyCode());
            if (arg0.getKeyCode()==10) {
                String name = textField_in.getText();
                textField_out.setText(name);
            }
    
        }
    
    });
    textField_in.setBounds(173, 40, 86, 20);
    frame.getContentPane().add(textField_in);
    textField_in.setColumns(10);
    
    0 讨论(0)
提交回复
热议问题