JTextField类似placeholder的提示效果

textField1.addFocusListener(new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {
                if (DEFAULT_PLACEHOLDER.equals(textField1.getText())) {

                    textField1.setText("");
                    textField1.setForeground(new Color(50, 50, 50));
                }
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (textField1.getText().length() == 0) {
                    textField1.setText(DEFAULT_PLACEHOLDER);
                    textField1.setForeground(new Color(150, 150, 150));
                }

            }
        });
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。