Java: How do I do a “onclick” for TextField?

后端 未结 3 1757
长发绾君心
长发绾君心 2021-01-15 07:14

I want to make my text field clear the text when someone clicks it. How can I do this?

3条回答
  •  滥情空心
    2021-01-15 07:21

    Probably, you need addMouseListener().

    upd It would be smt like

    TextField a = ...;
      a.addMouseListener(new MouseAdapter(){
       public void mouseReleased(MouseEvent e) {
        //some stuff
       }
    });
    

    upd2 fix keyListener to MouseListener

提交回复
热议问题