使用DocumentFilter在JTextField中仅接受双精度值 [英] Accept only Double Values in a JTextField using DocumentFilter

查看:155
本文介绍了使用DocumentFilter在JTextField中仅接受双精度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

你将要使用一个< a href =http://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html#filter =nofollow> DocumentFilter



这将允许您在传入的内容到达文档之前过滤。



检查这些例子了解更多想法



您还可以尝试查看 JFormattedTxtField ,这可能会更容易,但是那个


的乐趣在哪里

Is there any way to accept only double values in a JTextField using documentfilter?

解决方案

You will want to use a DocumentFilter

This will allow you to "filter" the incoming content before it reaches the document.

Check out these examples for more ideas

You could also try look at a JFormattedTxtField which would probably be easier, but where's the fun in that

这篇关于使用DocumentFilter在JTextField中仅接受双精度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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