e609. Listening to all Focus changes between, a application

Source: Internet
Author: User

To listen to focus change events between components, install a listener with the keyboard focus manager. If you need the ability-veto (reject) a focus change, install a vetoable listener with the keyboard focus manager.

    Keyboardfocusmanager.getcurrentkeyboardfocusmanager (). Addpropertychangelistener (New FocusChangeListener ()); Keyboardfocusmanager.getcurrentkeyboardfocusmanager (). Addvetoablechangelistener (New FocusVetoableChangeListener        ());             Class Focuschangelistener implements PropertyChangeListener {public void PropertyChange (Propertychangeevent evt) {            Component Oldcomp = (Component) evt.getoldvalue ();                Component Newcomp = (Component) evt.getnewvalue (); if ("Focusowner". Equals (Evt.getpropertyname ())) {if (Oldcomp = = null) {//the Newcomp                Component gained the focus} else {//The Oldcomp component lost the focus                    }} else if ("Focusedwindow". Equals (Evt.getpropertyname ())) {if (Oldcomp = = null) { The Newcomp window gained the focus} else {//the Oldcomp window lostThe Focus}}}} class Focusvetoablechangelistener implements Vetoablechangeli Stener {public void Vetoablechange (Propertychangeevent evt) throws propertyvetoexception {Component ol            Dcomp = (Component) evt.getoldvalue ();                Component Newcomp = (Component) evt.getnewvalue (); if ("Focusowner". Equals (Evt.getpropertyname ())) {if (Oldcomp = = null) {//the Newcomp                Component would gain the focus} else {//The Oldcomp component would lose the focus                    }} else if ("Focusedwindow". Equals (Evt.getpropertyname ())) {if (Oldcomp = = null) { The Newcomp window would gain the focus} else {//the Oldcomp win  Dow would lose the focus}} Boolean Vetofocuschange =false; if (Vetofocuschange) {throw new Propertyvetoexception ("Message", evt); }        }

related Examples

e609. Listening to all Focus changes between, a application

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.