Java Code Examples for java.awt.Component#isFocusable()

The following examples show how to use java.awt.Component#isFocusable() . 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: LegacyGlueFocusTraversalPolicy.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 2
Source File: LegacyGlueFocusTraversalPolicy.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 3
Source File: LegacyGlueFocusTraversalPolicy.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 4
Source File: LegacyGlueFocusTraversalPolicy.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 5
Source File: LegacyGlueFocusTraversalPolicy.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 6
Source File: LegacyGlueFocusTraversalPolicy.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 7
Source File: LegacyGlueFocusTraversalPolicy.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 8
Source File: LegacyGlueFocusTraversalPolicy.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 9
Source File: LegacyGlueFocusTraversalPolicy.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 10
Source File: LegacyGlueFocusTraversalPolicy.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 11
Source File: LegacyGlueFocusTraversalPolicy.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 12
Source File: EventQueueWait.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private static void generateFocusEvents(Component c) {
    if (c == focusComponent || !c.isFocusable()) {
        return;
    }
    if (focusComponent != null) {
        dispatchEvent(new FocusEvent(focusComponent, FocusEvent.FOCUS_LOST, false, c));
    }
    dispatchEvent(new FocusEvent(c, FocusEvent.FOCUS_GAINED, false, focusComponent));
}
 
Example 13
Source File: CloseTabPaneUI.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
boolean requestMyFocusForVisibleComponent() {
	Component visibleComponent = getVisibleComponent();
	if (visibleComponent.isFocusable()) {
		visibleComponent.requestFocus();
		return true;
	}
	else if (visibleComponent instanceof JComponent) {
		if (((JComponent) visibleComponent).requestFocusInWindow()) {
			return true;
		}
	}
	return false;
}
 
Example 14
Source File: OutlineView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void processComponentKeyEvent(KeyEvent e) {
    Component editorComponent = getEditorComponent();
    if (editorComponent != null && editorComponent.isFocusable()) {
        // The event should go to the editor component
        editorComponent.requestFocusInWindow();
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
    } else {
        super.processComponentKeyEvent(e);
    }
}
 
Example 15
Source File: BasicOutlookBarUI.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
protected boolean requestFocusForVisibleComponent0() {
  Component visibleComponent = getVisibleComponent();
  if (visibleComponent.isFocusable()) {
    visibleComponent.requestFocus();
    return true;
  } else if (visibleComponent instanceof JComponent) {
    if (((JComponent)visibleComponent).requestDefaultFocus()) { return true; }
  }
  return false;
}
 
Example 16
Source File: ProfilerPopup.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static boolean focusable(Component c) {
    if (c instanceof JLabel || c instanceof Box.Filler) return false;
    return c.isVisible() && c.isEnabled() && c.isFocusable();
}
 
Example 17
Source File: ProfilerToolbar.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
protected boolean focusable(Component c) {
    return c.isVisible() && c.isEnabled() && c.isFocusable();
}
 
Example 18
Source File: PFocusTraversalPolicy.java    From PolyGlot with MIT License 4 votes vote down vote up
@Override
protected boolean accept(final Component c) {
    return c.isFocusable() && super.accept(c);
}
 
Example 19
Source File: ProfilerPopup.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private static boolean focusable(Component c) {
    if (c instanceof JLabel || c instanceof Box.Filler) return false;
    return c.isVisible() && c.isEnabled() && c.isFocusable();
}
 
Example 20
Source File: FlatInspector.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
private String buildToolTipText( Component c ) {
	String name = c.getClass().getName();
	name = name.substring( name.lastIndexOf( '.' ) + 1 );

	String text =
		"Class: " + name + " (" + c.getClass().getPackage().getName() + ")\n" +
		"Size: " + c.getWidth() + ',' + c.getHeight() + "  @ " + c.getX() + ',' + c.getY() + '\n';

	if( c instanceof Container )
		text += "Insets: " + toString( ((Container)c).getInsets() ) + '\n';

	Insets margin = null;
	if( c instanceof AbstractButton )
		margin = ((AbstractButton) c).getMargin();
	else if( c instanceof JTextComponent )
		margin = ((JTextComponent) c).getMargin();
	else if( c instanceof JMenuBar )
		margin = ((JMenuBar) c).getMargin();
	else if( c instanceof JToolBar )
		margin = ((JToolBar) c).getMargin();

	if( margin != null )
		text += "Margin: " + toString( margin ) + '\n';

	Dimension prefSize = c.getPreferredSize();
	Dimension minSize = c.getMinimumSize();
	Dimension maxSize = c.getMaximumSize();
	text += "Pref size: " + prefSize.width + ',' + prefSize.height + '\n' +
		"Min size: " + minSize.width + ',' + minSize.height + '\n' +
		"Max size: " + maxSize.width + ',' + maxSize.height + '\n';

	if( c instanceof JComponent )
		text += "Border: " + toString( ((JComponent)c).getBorder() ) + '\n';

	text += "Background: " + toString( c.getBackground() ) + '\n' +
		"Foreground: " + toString( c.getForeground() ) + '\n' +
		"Font: " + toString( c.getFont() ) + '\n';

	if( c instanceof JComponent ) {
		try {
			Field f = JComponent.class.getDeclaredField( "ui" );
			f.setAccessible( true );
			Object ui = f.get( c );
			text += "UI: " + (ui != null ? ui.getClass().getName() : "null") + '\n';
		} catch( NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex ) {
			// ignore
		}
	}

	if( c instanceof Container ) {
		LayoutManager layout = ((Container)c).getLayout();
		if( layout != null )
			text += "Layout: " + layout.getClass().getName() + '\n';
	}

	text += "Enabled: " + c.isEnabled() + '\n';
	text += "Opaque: " + c.isOpaque() + (c instanceof JComponent &&
		FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") + '\n';
	if( c instanceof AbstractButton )
		text += "ContentAreaFilled: " + ((AbstractButton)c).isContentAreaFilled() + '\n';
	text += "Focusable: " + c.isFocusable() + '\n';
	text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n';
	text += "Parent: " + (c.getParent() != null ? c.getParent().getClass().getName() : "null");

	if( inspectParentLevel > 0 )
		text += "\n\nParent level: " + inspectParentLevel;

	if( inspectParentLevel > 0 )
		text += "\n(press Ctrl/Shift to increase/decrease level)";
	else
		text += "\n\n(press Ctrl key to inspect parent)";

	return text;
}