Java Code Examples for com.alee.utils.SwingUtils#hasFocusOwner()
The following examples show how to use
com.alee.utils.SwingUtils#hasFocusOwner() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebInnerPopup.java From weblaf with GNU General Public License v3.0 | 6 votes |
/** * Returns whether one of focusable children is focused or not. * * @return true if one of focusable children is focused, false otherwise */ public boolean isChildFocused () { for ( final WeakReference<Component> focusableChild : focusableChildren ) { final Component component = focusableChild.get (); if ( component != null ) { if ( SwingUtils.hasFocusOwner ( component ) ) { return true; } } } return false; }
Example 2
Source File: ComboBoxMouseWheelScrollBehavior.java From weblaf with GNU General Public License v3.0 | 5 votes |
@Override public void mouseWheelMoved ( @NotNull final MouseWheelEvent e ) { if ( component.isEnabled () && SwingUtils.hasFocusOwner ( component ) ) { // Changing selection in case index actually changed final int index = component.getSelectedIndex (); final int newIndex = MathUtils.limit ( 0, index + e.getWheelRotation (), component.getModel ().getSize () - 1 ); if ( newIndex != index ) { component.setSelectedIndex ( newIndex ); } } }
Example 3
Source File: ComponentTransition.java From weblaf with GNU General Public License v3.0 | 4 votes |
/** * Transition call */ protected void performTransitionImpl ( final Component content ) { // Ignore repeated change or change to same content if ( lastContent == content ) { return; } // Remember new content to which area is switched lastContent = content; // When animation disabled or component is not shown performing transition instantly if ( !canAnimate () ) { finishTransitionImpl ( content ); return; } // Check for old transition if ( transition != null ) { if ( isAnimating () ) { // Cancel old transition if it is already running transition.cancelTransition (); } else { // Block transition if it has not yet started transition.setBlocked ( true ); } } // Marking new transition start animating = true; // Width and height final int width = getWidth (); final int height = getHeight (); // Current content image final BufferedImage currentSnapshot; if ( transition != null ) { currentSnapshot = transition.getOtherImage (); } else { final Component currentContent = getComponentCount () > 0 ? getComponent ( 0 ) : null; currentSnapshot = SwingUtils.createComponentSnapshot ( currentContent, width, height ); } // Enabling focus for transition time so you can focus the panel // It will transfer focus onto inner components (or next, if no focusable inner components available) when transition ends setFocusable ( true ); // Passing the focus from subcomponents onto the transition panel if ( restoreFocus && SwingUtils.hasFocusOwner ( ComponentTransition.this ) ) { // Focus handler required to wait for focus change // This is required to handle focus properly and have atleast one component focused withing window of calendar // Otherwise focus will be lost and window may become "bugged" and may require additiona user actions in some cases final FocusAdapter focusHandle = new FocusAdapter () { @Override public void focusGained ( final FocusEvent e ) { removeFocusListener ( this ); continueTransitionImpl ( content, width, height, currentSnapshot ); } }; addFocusListener ( focusHandle ); // Requesting focus into transition panel if ( !ComponentTransition.this.requestFocusInWindow () ) { // Request focus failed, continue without changing focus removeFocusListener ( focusHandle ); continueTransitionImpl ( content, width, height, currentSnapshot ); } } else { continueTransitionImpl ( content, width, height, currentSnapshot ); } }