JTextField中的示例文本 [英] Example text in JTextField

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

问题描述

我正在寻找一种方法将示例文本放入swing JTextField并使其变灰。只要在该文本字段中输入任何内容,示例文本就会消失。有些类似于stackoverflow在用户使用title字段发布问题时所执行的操作。

I am looking for a way to put example text into a swing JTextField and have it grayed out. The example text should then disappear as soon as any thing is entered into that text field. Some what similar to what stackoverflow does when a user is posting a question with the title field.

我想要它,如果它已经是JTextField的扩展实现,那么我可以把它作为一个简单的替代品放入。来自swingx的任何东西都可行。我想如果没有一种简单的方法可以做到这一点,我的选择可能是覆盖JTextField的paint方法做一些可能的事情。

I would like it if it was already a extended implementation of JTextField so that I can just drop it in as a simple replacement. Anything from swingx would work. I guess if there is not an easy way to do this my option will probably be to override the paint method of JTextField do something that way maybe.

谢谢

推荐答案

文本提示类提供了所需的功能,而不使用自定义的JTextField。

The Text Prompt class provides the required functionality without using a custom JTextField.

这篇关于JTextField中的示例文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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