Readonly JFormattedTextField [英] Readonly JFormattedTextField

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

问题描述

假设 JFormattedTextField 已启用并包含格式化程序,有没有办法让它只读?使用 JTextField ,我们只需要提供一个自定义 Document 并在那里进行所有控制,但是使用 JFormattedTextField 我认为事情是因为我们不想弄乱它的文档过滤器,所以要复杂得多。我真的需要这个功能。那么,有没有办法实现这个目标?

Supossing that a JFormattedTextField is enabled and contains a formatter, is there a way to make it readonly? With a JTextField, we just need to suply a custom Document and do all the control there, but with a JFormattedTextField I suppose that things are a little more complicated as we don't want to mess with its document filter. I really need this feature. So, is there a way to achieve this?

更新:只是我的意见,但似乎 JFormattedTextField 设计得很糟糕感觉它没有为这个简单的问题留下简单的解决方案。

UPDATE: Just my opinion, but it seems that the JFormattedTextField is so bad designed in this sense that it leaves no easy solution to this simple problem.

Marcos

推荐答案

你可以简单地使用:

JFormattedTextField field = new JFormattedTextField();
// ...
field.setEditable(false);

就像 JTextField 一样,因为 JFormattedTextField extends JTextField

just like for the JTextField since JFormattedTextField extends JTextField

查看 javadoc

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

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