有没有选项JTEXTFIELD可以检查特定格式的输入吗?

发布于 2025-01-30 08:56:36 字数 51 浏览 2 评论 0原文

我想使用JTEXTFIELD以YYYY-MM-DD格式输入日期。是否有可能验证输入格式?

I want to use a JTextField to enter dates in the YYYY-MM-DD format. Is there a possibility to validate the entered format?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初相遇 2025-02-06 08:56:36

您正在询问输入验证。使用事件侦听器自己执行此操作,该事件侦听器

  • 每当字段内容更改
  • 或字段失去焦点时触发
  • ,或者按下对话框的确定​​按钮时

使用哪种机制,取决于您想要提供的速度以及验证的代价高昂。

作为替代方案,您可以参考

You are asking about Input Validation. Do this yourself with an event listener that is triggered

  • either whenever the field content changes,
  • or when the field loses focus
  • or when the dialog's ok button is pressed

Which mechanism you use depends on how quickly you want to give feedback and how costly a validation is.

As an alternative you can refer to the Swing Frameworks Input Validation features.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文