< prev index next >
src/java.desktop/share/classes/java/awt/ContainerOrderFocusTraversalPolicy.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -26,10 +26,18 @@
import java.util.List;
import java.util.ArrayList;
import sun.util.logging.PlatformLogger;
+import java.util.Enumeration;
+import sun.awt.SunToolkit;
+import javax.swing.AbstractButton;
+import javax.swing.ButtonGroup;
+import javax.swing.ButtonModel;
+import javax.swing.JToggleButton;
+
+
/**
* A FocusTraversalPolicy that determines traversal order based on the order
* of child Components in a Container. From a particular focus cycle root, the
* policy makes a pre-order traversal of the Component hierarchy, and traverses
* a Container's children according to the ordering of the array returned by
@@ -583,10 +591,34 @@
protected boolean accept(Component aComponent) {
if (!aComponent.canBeFocusOwner()) {
return false;
}
+ if (SunToolkit.isInstanceOf(aComponent,
+ "javax.swing.JToggleButton")) {
+ ButtonModel model = ((JToggleButton)aComponent).getModel();
+ if (model != null) {
+ ButtonGroup group = model.getGroup();
+ if (group != null) {
+ Enumeration<AbstractButton> elements =
+ group.getElements();
+ int idx = 0;
+ while (group.getElements().hasMoreElements()) {
+ AbstractButton member = elements.nextElement();
+ if (member instanceof JToggleButton &&
+ member.isVisible() && member.isDisplayable() &&
+ member.isEnabled() && member.isFocusable()) {
+ if (member == aComponent) {
+ return idx == 0;
+ }
+ idx++;
+ }
+ }
+ }
+ }
+ }
+
// 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();
< prev index next >