e606. Determining Which Component or Window Has the Focus

    // null is returned if none of the components in this application has the focus
    Component compFocusOwner =
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    
    // null is returned if none of the windows in this application has the focus
    Window windowFocusOwner =
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    
    // Use this method to determine whether a particular component has the focus
    boolean b = component.isFocusOwner();

 

Related Examples
posted @ 2018-09-06 08:31  borter  阅读(160)  评论(0编辑  收藏  举报