JTextField上的自定义渲染器.是否有可能 ? [英] Custom renderer on a JTextField. Is it possible ?

查看:122
本文介绍了JTextField上的自定义渲染器.是否有可能 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个看起来像JTextField的组件(相同的边框,阴影,圆角等),但是要显示一些带有文本的图形.

I need to create component that looks like JTextField (same borders, shadows, rounded corners etc) but for displaying some graphic with text.

是否可以为JTextField创建类似渲染器的内容? 或者 基于JPanel创建自定义组件,但是如何使其与JTextField相同

Is it possible to create something like renderer for a JTextField? Or Create custom component based on JPanel, but how to force it to looks same as JTextField

另一个复杂之处在于,应用程序将在动态更改的不同LAF上运行.

Another complication is that application will be running on different LAF's changed on the fly.

您有什么主意吗?

推荐答案

否,Swing不提供您可以在其之上构建的任何DefaultTextFieldRenderer或TextFieldRendere接口. 您提到喜欢L& F感知的渲染;多数民众赞成已经解决了:您必须为每个L& F实现一个UI才能将图形渲染到TextField中-对于某些选定的 来说,这是可行的(比如说Windows/Mac/Metal) ,但对于用户可能想使用的任何 L& F来说,几乎没有(如果您留给他们选择的话).

No, Swing does not provide any DefaultTextFieldRenderer or TextFieldRendere interface you can build on top of. You mention you like L&F aware rendering; thats already part of the answer: you would have to implement a UI for each L&F to render graphics into a TextField - this may be feasible for a selected few (lets say Windows/Mac/Metal), but hardly for any L&F that a user may want to use (if you leave them a choice).

让我猜,您需要在该字段中显示某种状态/验证图标.做第二件事,并将其显示为该字段的 next 图标,而不是显示在TextField本身中.麻烦少了:)

Let me guess, you have the requirement to display some sort of status/validation icon with the field. Do the next best thing and display that as an icon next to the field, not in the TextField itself. Much less trouble :)

这篇关于JTextField上的自定义渲染器.是否有可能 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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