如何在JTextField java中显示默认消息 [英] How to display a default message in JTextField java

查看:573
本文介绍了如何在JTextField java中显示默认消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个带有消息的JTextField作为deafult。但不是作为正确的文本,而是作为对JTextField内部输入内容的评论。
因此,如果我输入jtf.getText(),它将返回null或空,因为它只是在那里打印的注释。当你点击它然后它消失了,你可以写任何你想要的东西。有没有办法做这样的事情?

I want to create a JTextField with a message inside as a deafult. But not as a proper text but as a comment about what to type inside the JTextField. So if i type jtf.getText() it returns null or empty because it is just a comment that was printed there. When you click on it then it disappears and you can write whatever you want on it. Is there any method to do such a thing?

推荐答案

我相信你想要的是输入提示在文本字段中,如下图所示:

I believe what you want is input hint in the text field, something like the image below:

检查 xswingx 库可以做到这一点。

Check xswingx library which can do this.

这篇关于如何在JTextField java中显示默认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆