按JTextField时清除文本

时间:2018-01-20 02:48:49

标签: java swing netbeans

我每次点击它时都试图删除JTextField的文本。我做了一个addFocusListene但是没有出现任何消​​息。我不明白为什么

        nick = new JTextField("nick", 5);
    add(nick);
    nick.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            nick.setText("");

        }

        public void focusLost(FocusEvent e) {
            // nothing
        }
    });

    JLabel texto = new JLabel("CLIENTE");
    add(texto);

    ip = new JTextField("Introduce la IP del destinatario", 16);
    add(ip);
    ip.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            ip.setText("");

        }

        public void focusLost(FocusEvent e) {
            // nothing
        }
    });

0 个答案:

没有答案