本文整理匯總了Java中java.awt.FocusTraversalPolicy.getFirstComponent方法的典型用法代碼示例。如果您正苦於以下問題:Java FocusTraversalPolicy.getFirstComponent方法的具體用法?Java FocusTraversalPolicy.getFirstComponent怎麽用?Java FocusTraversalPolicy.getFirstComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.FocusTraversalPolicy
的用法示例。
在下文中一共展示了FocusTraversalPolicy.getFirstComponent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFirstComponent
import java.awt.FocusTraversalPolicy; //導入方法依賴的package包/類
public Component getFirstComponent(Container aContainer) {
Container root = (aContainer.isFocusCycleRoot())
? aContainer
: aContainer.getFocusCycleRootAncestor();
// Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
// traversal policy is non-legacy, then honor it.
if (root != null) {
FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
if (policy != gluePolicy) {
return policy.getFirstComponent(root);
}
comparator.setComponentOrientation(root.getComponentOrientation());
return layoutPolicy.getFirstComponent(root);
}
return null;
}
示例2: getFirstComponent
import java.awt.FocusTraversalPolicy; //導入方法依賴的package包/類
/**
* Returns the first component.
* @return the first component
* @param aContainer a container
*/
public Component getFirstComponent(Container aContainer) {
Container root = (aContainer.isFocusCycleRoot())
? aContainer
: aContainer.getFocusCycleRootAncestor();
// Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
// traversal policy is non-legacy, then honor it.
if (root != null) {
FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
if (policy != gluePolicy) {
return policy.getFirstComponent(root);
}
comparator.setComponentOrientation(root.getComponentOrientation());
return layoutPolicy.getFirstComponent(root);
}
return null;
}
示例3: focusFirstComponentNow
import java.awt.FocusTraversalPolicy; //導入方法依賴的package包/類
private static void focusFirstComponentNow(JComponent component) {
FocusTraversalPolicy focusPolicy = component.getFocusTraversalPolicy();
if (component instanceof JTextComponent || component instanceof JComboBox || component instanceof JCheckBox) {
component.requestFocus();
} else if (focusPolicy != null && focusPolicy.getFirstComponent(component) != null) {
focusPolicy.getFirstComponent(component).requestFocus();
} else {
FocusManager.getCurrentManager().focusNextComponent(component);
}
}
示例4: actionPerformed
import java.awt.FocusTraversalPolicy; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
setFocusCycleRoot(false);
try {
Container con = ETable.this.getFocusCycleRootAncestor();
if (con != null) {
/*
Component target = ETable.this;
if (getParent() instanceof JViewport) {
target = getParent().getParent();
if (target == con) {
target = ETable.this;
}
}
*/
EventObject eo = EventQueue.getCurrentEvent();
boolean backward = false;
if (eo instanceof KeyEvent) {
backward =
(((KeyEvent) eo).getModifiers()
& KeyEvent.SHIFT_MASK)
!= 0 && (((KeyEvent) eo).getModifiersEx() &
KeyEvent.SHIFT_DOWN_MASK) != 0;
}
Component c = ETable.this;
Component to;
Container parentWithFTP = null;
do {
FocusTraversalPolicy ftp = con.getFocusTraversalPolicy();
to = backward ? ftp.getComponentBefore(con, c)
: ftp.getComponentAfter(con, c);
if (to == ETable.this) {
to = backward ? ftp.getFirstComponent(con)
: ftp.getLastComponent(con);
}
if (to == ETable.this) {
parentWithFTP = con.getParent();
if (parentWithFTP != null) {
parentWithFTP = parentWithFTP.getFocusCycleRootAncestor();
}
if (parentWithFTP != null) {
c = con;
con = parentWithFTP;
}
}
} while (to == ETable.this && parentWithFTP != null);
if (to != null) {
to.requestFocus();
}
}
} finally {
setFocusCycleRoot(true);
}
}
示例5: getComponentAfter
import java.awt.FocusTraversalPolicy; //導入方法依賴的package包/類
@Override
public Component getComponentAfter(Container container,
Component component) {
// Fix awt bug looking for ComboBoxEditor instead ComboBox
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6205817
if (component.getParent() instanceof JComboBox)
component = component.getParent();
int index = components.indexOf(component);
if (index == -1) { // not owner
Container childContainer = getTopmostProvider(container, component);
if (childContainer == null)
return getFirstComponent(container);
FocusTraversalPolicy ftp = childContainer.getFocusTraversalPolicy();
if (ftp != null && ftp != this) {
Component next = ftp.getComponentAfter(childContainer, component);
if (next != ftp.getFirstComponent(container))
return next;
// child cycle
do {
index = components.indexOf(childContainer);
childContainer = childContainer.getParent();
} while (index == -1 || childContainer == null);
if (index == -1) {
log.warn("I can't figure what is the next component");
return getFirstComponent(container);
}
}
}
index++;
if (index < components.size() && index >= 0) {
Component c = getComponent(index);
if (c.isEnabled() && c.isFocusable())
return c;
else
return getComponentAfter(container, c);
}
return getFirstComponent(container);
}