可编辑的JComboBox限制长度

发布于 2024-12-20 07:37:04 字数 54 浏览 2 评论 0原文

我有一个可编辑的 JCombobox,需要设置用户可以设置的字符数限制。

谢谢

i have an editable JCombobox and need to set a limit to the number of characters that can be set by the user.

Thanks

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

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

发布评论

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

评论(2

赏烟花じ飞满天 2024-12-27 07:37:04

既然您提到了字符,我假设您的 JCombobox 上的编辑器可以是 JTextField。在这种情况下,您可以通过设置自定义 Document 来限制 JTextField 接受的字符数,如详细说明此处

Since you mentions characters, I assume the editor on your JCombobox can be a JTextField. In that case, you can limit the number of characters the JTextField accepts by setting a custom Document, as explained in full detail here

再见回来 2024-12-27 07:37:04

您可以修改组合框编辑器的最大字符数,如下所示(最多 4 个字符):

JComboBox comboBox==new JComboBox();
ComboBoxEditor editor = comboBox.getEditor();
JTextField textField = (JTextField)editor.getEditorComponent();
textField.setDocument(new JTextFieldLimit(4));

You can modify maximum number of characters changing the comboBox editor as you can see below (Max 4 characters):

JComboBox comboBox==new JComboBox();
ComboBoxEditor editor = comboBox.getEditor();
JTextField textField = (JTextField)editor.getEditorComponent();
textField.setDocument(new JTextFieldLimit(4));

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