本文整理汇总了Java中java.awt.peer.ComponentPeer.isFocusable方法的典型用法代码示例。如果您正苦于以下问题:Java ComponentPeer.isFocusable方法的具体用法?Java ComponentPeer.isFocusable怎么用?Java ComponentPeer.isFocusable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.peer.ComponentPeer
的用法示例。
在下文中一共展示了ComponentPeer.isFocusable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldFocusOnClick
import java.awt.peer.ComponentPeer; //导入方法依赖的package包/类
public static boolean shouldFocusOnClick(Component component) {
boolean acceptFocusOnClick = false;
// A component is generally allowed to accept focus on click
// if its peer is focusable. There're some exceptions though.
// CANVAS & SCROLLBAR accept focus on click
final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
if (component instanceof Canvas ||
component instanceof Scrollbar)
{
acceptFocusOnClick = true;
// PANEL, empty only, accepts focus on click
} else if (component instanceof Panel) {
acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);
// Other components
} else {
ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
}
return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
示例2: accept
import java.awt.peer.ComponentPeer; //导入方法依赖的package包/类
/**
* Determines whether a Component is an acceptable choice as the new
* focus owner. The Component must be visible, displayable, and enabled
* to be accepted. If client code has explicitly set the focusability
* of the Component by either overriding
* <code>Component.isFocusTraversable()</code> or
* <code>Component.isFocusable()</code>, or by calling
* <code>Component.setFocusable()</code>, then the Component will be
* accepted if and only if it is focusable. If, however, the Component is
* relying on default focusability, then all Canvases, Labels, Panels,
* Scrollbars, ScrollPanes, Windows, and lightweight Components will be
* rejected.
*
* @param aComponent the Component whose fitness as a focus owner is to
* be tested
* @return <code>true</code> if aComponent meets the above requirements;
* <code>false</code> otherwise
*/
protected boolean accept(Component aComponent) {
if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
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;
}
}
}
boolean focusable = aComponent.isFocusable();
if (aComponent.isFocusTraversableOverridden()) {
return focusable;
}
ComponentPeer peer = aComponent.getPeer();
return (peer != null && peer.isFocusable());
}
示例3: shouldFocusOnClick
import java.awt.peer.ComponentPeer; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
boolean acceptFocusOnClick = false;
// A component is generally allowed to accept focus on click
// if its peer is focusable. There're some exceptions though.
// CANVAS & SCROLLBAR accept focus on click
if (component instanceof Canvas ||
component instanceof Scrollbar)
{
acceptFocusOnClick = true;
// PANEL, empty only, accepts focus on click
} else if (component instanceof Panel) {
acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);
// Other components
} else {
ComponentPeer peer = (component != null ? component.getPeer() : null);
acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
}
return acceptFocusOnClick &&
AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
示例4: accept
import java.awt.peer.ComponentPeer; //导入方法依赖的package包/类
/**
* Determines whether a Component is an acceptable choice as the new
* focus owner. The Component must be visible, displayable, and enabled
* to be accepted. If client code has explicitly set the focusability
* of the Component by either overriding
* {@code Component.isFocusTraversable()} or
* {@code Component.isFocusable()}, or by calling
* {@code Component.setFocusable()}, then the Component will be
* accepted if and only if it is focusable. If, however, the Component is
* relying on default focusability, then all Canvases, Labels, Panels,
* Scrollbars, ScrollPanes, Windows, and lightweight Components will be
* rejected.
*
* @param aComponent the Component whose fitness as a focus owner is to
* be tested
* @return {@code true} if aComponent meets the above requirements;
* {@code false} otherwise
*/
protected boolean accept(Component aComponent) {
if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
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;
}
}
}
boolean focusable = aComponent.isFocusable();
if (aComponent.isFocusTraversableOverridden()) {
return focusable;
}
ComponentPeer peer = aComponent.peer;
return (peer != null && peer.isFocusable());
}