A pit that is encountered when an editable jcombobox is used, and if the JComboBox focus is still present, the current edit value is not obtained.

Source: Internet
Author: User

There is only one jcombobox and one jbutton on the interface, click JButton Print JComboBox the current value.

If the JButton focusable is set to false, the focus cannot be obtained.

Then when editing the value of JComboBox, click JButton to Print Cmb.getselecteditem (). toString (), not the value in the current JComboBox edit box, but the value of the last selection.

This means that after editing the JComboBox, you must wait for JComboBox to lose focus, and the current edit value will be "submitted" before you can use GetSelectedItem to get it.


When you need attention, it is useless to use other.requestfocusinwindows () in the JButton click Response function.

The order of the internal mechanisms here is not yet clear. In short, it is a lesson to be able to edit jcombobox and JButton when cooperating, JButton need to pay attention to focusable attributes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.