本文整理汇总了Java中java.awt.FocusTraversalPolicy.getComponentBefore方法的典型用法代码示例。如果您正苦于以下问题:Java FocusTraversalPolicy.getComponentBefore方法的具体用法?Java FocusTraversalPolicy.getComponentBefore怎么用?Java FocusTraversalPolicy.getComponentBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.FocusTraversalPolicy
的用法示例。
在下文中一共展示了FocusTraversalPolicy.getComponentBefore方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import java.awt.FocusTraversalPolicy; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
int selIndexBefore = getSelectedIndex();
defaultAction.actionPerformed( e );
int selIndexCurrent = getSelectedIndex();
if( selIndexBefore != selIndexCurrent )
return;
if( focusNext && 0 == selIndexCurrent && getModel().getSize() > 1 && getModel().getSize() > getColumnCount() )
return;
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Container container = kfm.getCurrentFocusCycleRoot();
FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
if( null == policy )
policy = kfm.getDefaultFocusTraversalPolicy();
Component next = focusNext ? policy.getComponentAfter( container, CategoryList.this )
: policy.getComponentBefore( container, CategoryList.this );
if( null != next && next instanceof CategoryButton ) {
clearSelection();
next.requestFocus();
}
}
示例2: getComponentBefore
import java.awt.FocusTraversalPolicy; //导入方法依赖的package包/类
public Component getComponentBefore(Container aContainer,
Component aComponent)
{
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.getComponentBefore(root, aComponent);
}
comparator.setComponentOrientation(root.getComponentOrientation());
return layoutPolicy.getComponentBefore(root, aComponent);
}
return null;
}
示例3: getComponentBefore
import java.awt.FocusTraversalPolicy; //导入方法依赖的package包/类
/**
* Returns the component before.
* @return the component before
* @param aContainer a container
* @param aComponent a component
*/
public Component getComponentBefore(Container aContainer,
Component aComponent)
{
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.getComponentBefore(root, aComponent);
}
comparator.setComponentOrientation(root.getComponentOrientation());
return layoutPolicy.getComponentBefore(root, aComponent);
}
return null;
}
示例4: getFocusableComponents
import java.awt.FocusTraversalPolicy; //导入方法依赖的package包/类
/** Returns a set of all the components that
* can have the keyboard focus.
* <P>My first implementation involved of this concept
* simply involved asking JCompnonents if they were
* focusable, but in the <code>FilledButtonTest</code> this
* resulted in shifting focus to the ContentPane. Although
* it is technically focusable: if I used the tab key
* I did <i>not</i> get this result. So I studied
* the inner workings for Component.transferFocus()
* and ended up with a method that involved
* calls to <code>getFocusCycleRootAncestor()</code>,
* and <code>getFocusTraversalPolicy()</code>.
* <P>(Also credit goes to Werner for originally tipping me off
* towards looking at FocusTraversalPolicies.)
* @param currentFocusOwner the current focus owner.
* @return all the JComponents that can receive the focus.
*/
public static Set<Component> getFocusableComponents(Component currentFocusOwner) {
HashSet<Component> set = new HashSet<Component>();
set.add(currentFocusOwner);
Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
Component comp = currentFocusOwner;
while (rootAncestor != null &&
!(rootAncestor.isShowing() &&
rootAncestor.isFocusable() &&
rootAncestor.isEnabled()))
{
comp = rootAncestor;
rootAncestor = comp.getFocusCycleRootAncestor();
}
if (rootAncestor != null) {
FocusTraversalPolicy policy =
rootAncestor.getFocusTraversalPolicy();
Component toFocus = policy.getComponentAfter(rootAncestor, comp);
while(toFocus!=null && set.contains(toFocus)==false) {
set.add(toFocus);
toFocus = policy.getComponentAfter(rootAncestor, toFocus);
}
toFocus = policy.getComponentBefore(rootAncestor, comp);
while(toFocus!=null && set.contains(toFocus)==false) {
set.add(toFocus);
toFocus = policy.getComponentBefore(rootAncestor, toFocus);
}
}
return set;
}
示例5: onTakeFocus
import java.awt.FocusTraversalPolicy; //导入方法依赖的package包/类
@Override
public void onTakeFocus(CefBrowser browser, boolean next) {
if (browser == null)
return;
browser.setFocus(false);
Container parent = browser.getUIComponent().getParent();
if (parent != null) {
FocusTraversalPolicy policy = null;
while (parent != null) {
policy = parent.getFocusTraversalPolicy();
if (policy != null)
break;
parent = parent.getParent();
}
if (policy != null) {
Component nextComp = next ? policy.getComponentAfter(parent, browser.getUIComponent())
: policy.getComponentBefore(parent, browser.getUIComponent());
if (nextComp == null) {
policy.getDefaultComponent(parent).requestFocus();
} else {
nextComp.requestFocus();
}
}
}
focusedBrowser_ = null;
if (focusHandler_ != null)
focusHandler_.onTakeFocus(browser, next);
}
示例6: getFocusableComponents
import java.awt.FocusTraversalPolicy; //导入方法依赖的package包/类
/** Returns a set of all the components that
* can have the keyboard focus.
* <P>My first implementation involved of this concept
* simply involved asking JCompnonents if they were
* focusable, but in the <code>FilledButtonTest</code> this
* resulted in shifting focus to the ContentPane. Although
* it is technically focusable: if I used the tab key
* I did <i>not</i> get this result. So I studied
* the inner workings for Component.transferFocus()
* and ended up with a method that involved
* calls to <code>getFocusCycleRootAncestor()</code>,
* and <code>getFocusTraversalPolicy()</code>.
* <P>(Also credit goes to Werner for originally tipping me off
* towards looking at FocusTraversalPolicies.)
* @param currentFocusOwner the current focus owner.
* @return all the JComponents that can receive the focus.
*/
public static Set<Component> getFocusableComponents(Component currentFocusOwner) {
HashSet<Component> set = new HashSet<Component>();
set.add(currentFocusOwner);
Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
Component comp = currentFocusOwner;
while (rootAncestor != null &&
!(rootAncestor.isShowing() &&
rootAncestor.isFocusable() &&
rootAncestor.isEnabled()))
{
comp = rootAncestor;
rootAncestor = comp.getFocusCycleRootAncestor();
}
if (rootAncestor != null) {
FocusTraversalPolicy policy =
rootAncestor.getFocusTraversalPolicy();
Component toFocus = policy.getComponentAfter(rootAncestor, comp);
// final Component startingPoint = currentFocusOwner;
while(toFocus!=null && set.contains(toFocus)==false) {
set.add(toFocus);
toFocus = policy.getComponentAfter(rootAncestor, toFocus);
}
toFocus = policy.getComponentBefore(rootAncestor, comp);
while(toFocus!=null && set.contains(toFocus)==false) {
set.add(toFocus);
toFocus = policy.getComponentBefore(rootAncestor, toFocus);
}
}
return set;
}
示例7: onTakeFocus
import java.awt.FocusTraversalPolicy; //导入方法依赖的package包/类
@Override
public void onTakeFocus(CefBrowser browser, boolean next) {
if (browser == null)
return;
browser.setFocus(false);
Container parent = browser.getUIComponent().getParent();
if (parent != null) {
FocusTraversalPolicy policy = null;
while (parent != null) {
policy = parent.getFocusTraversalPolicy();
if (policy != null)
break;
parent = parent.getParent();
}
if (policy != null) {
Component nextComp = next ? policy.getComponentAfter(parent, browser.getUIComponent())
: policy.getComponentBefore(parent, browser.getUIComponent());
if (nextComp == null) {
policy.getDefaultComponent(parent).requestFocus();
} else {
nextComp.requestFocus();
}
}
}
if (focusHandler_ != null)
focusHandler_.onTakeFocus(browser, next);
}
示例8: actionPerformed
import java.awt.FocusTraversalPolicy; //导入方法依赖的package包/类
public void actionPerformed(final ActionEvent e) {
Container ancestor = desktop.getFocusCycleRootAncestor();
if (ancestor == null) {
return;
}
FocusTraversalPolicy policy = ancestor.getFocusTraversalPolicy();
if (!(policy instanceof SortingFocusTraversalPolicy)) {
return;
}
SortingFocusTraversalPolicy sortingPolicy = (SortingFocusTraversalPolicy)policy;
boolean implicitEnabled = sortingPolicy.getImplicitDownCycleTraversal();
sortingPolicy.setImplicitDownCycleTraversal(false);
Component result = null;
String action = (String)getValue(NAME);
if ("navigateNext".equals(action)) {
result = policy.getComponentAfter(ancestor, desktop);
} else if ("navigatePrevious".equals(action)) {
result = policy.getComponentBefore(ancestor, desktop);
}
sortingPolicy.setImplicitDownCycleTraversal(implicitEnabled);
if (result != null) {
result.requestFocus();
}
}
示例9: 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);
}
}