在一个 jcombobox 中进行状态更改启用不同的 jcombobox

发布于 2024-10-25 06:34:13 字数 359 浏览 0 评论 0原文

我有 7 个 jcomboboxes,比如说: 客户信息1 客户信息2 客户信息3 客户信息4 客户信息5 客户信息6 customerInfo7

除第一个之外的所有内容均设置为 setEnabled(false) 并具有 setSelectedItem("请从下拉菜单中选择客户")。我最难弄清楚如何监听 customerInfo1 上的状态更改,然后使 customerInfo2 setEnabled(true) 。并且,一旦启用了 customerInfo2,状态更改事件就会触发 customerInfo3 的相同事件,依此类推。基本上,我不希望启用给定的 customerInfo jcombobox,直到在前一个中选择了除最初设置之外的其他内容。非常感谢您明确而具体的帮助。

I have 7 jcomboboxes, say:
customerInfo1
customerInfo2
customerInfo3
customerInfo4
customerInfo5
customerInfo6
customerInfo7

All but the first one are set to setEnabled(false) and have setSelectedItem("Please Select a Customer from the dropdown menu"). I am having the hardest time figuring out how I would go about listening for a state change on customerInfo1 which would then make customerInfo2 setEnabled(true). And, once customerInfo2 is enabled have a state change event trigger the same thing for customerInfo3, and so on. Basically I don't want a given customerInfo jcombobox to be enabled until something other than what was initially set is selected in the preceding one. Your clear and specific help is much appreciated.

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

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

发布评论

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

评论(2

﹂绝世的画 2024-11-01 06:34:13

您可以在组合框上添加焦点侦听器,这样如果组合失去焦点,您就可以检查情况并采取相应的操作!

例如,

  if we have a combo box then we would add a focus listener on it and check the condition whether the check box is checked or not then add the required combobox.

     JComboBox jb1;
     jb1.addFocusListener(this);

这将在 main 中完成,并且以下代码在同一类中的其他方法中完成,

     public void focusLost(FocusEvent fe) 
     {
          //your code for enabling or disabling the combo box
     }

这应该执行所需的操作

问候
查兰吉特

you can add a focus listener on the combo boxes such that if a combo has lost focus then you can check about the condition and take your action accordingly!!!

eg

  if we have a combo box then we would add a focus listener on it and check the condition whether the check box is checked or not then add the required combobox.

     JComboBox jb1;
     jb1.addFocusListener(this);

this is to be done in main and the following code in other method in the same class

     public void focusLost(FocusEvent fe) 
     {
          //your code for enabling or disabling the combo box
     }

this should do the required thing

Regards
ChArAnJiT

后知后觉 2024-11-01 06:34:13

您需要在第一个组合框的更改事件上调用 JavaScript 方法。

假设如果您更改第一个组合框的状态,则会调用此 JavaScript 方法,并且它将根据您的意愿更改其他组合框的状态。

必须对所有其他组合框执行相同的操作。

You need to call a JavaScript method on change event of the first combo box.

Say if you change the state of the first combo box, this JavaScript method will be called and it will change the state of other combo boxes as u wish.

Same thing have to be done for all the other combo boxes.

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