-
Enhancement
-
Resolution: Duplicate
-
P4
-
8u20
-
None
When writing custom controls the skins often consist of one or more standard controls. These controls will have the focus when the user performs an edit (e.g. inside a TextField). However, the application using the custom control will not "see" the textfield but only the custom control. It would be good if methods were added to Node that would allow the application to check if something inside a node / parent currently has the focus.
Example:
public boolean hasFocus() {
if (isFocused()) {
return true;
}
for (Node c : getChildren()) {
if (c.isFocused()) {
return true;
}
if (c instanceof Parent) {
boolean internalFocus = isFocusInside((Parent) c);
if (internalFocus) {
return true;
}
}
}
return false;
}
private boolean isFocusInside(Parent p) {
for (Node c : getChildren()) {
if (c.isFocused()) {
return true;
}
if (c instanceof Parent) {
boolean internalFocus = isFocusInside((Parent) c);
if (internalFocus) {
return true;
}
}
}
return false;
}
Example:
public boolean hasFocus() {
if (isFocused()) {
return true;
}
for (Node c : getChildren()) {
if (c.isFocused()) {
return true;
}
if (c instanceof Parent) {
boolean internalFocus = isFocusInside((Parent) c);
if (internalFocus) {
return true;
}
}
}
return false;
}
private boolean isFocusInside(Parent p) {
for (Node c : getChildren()) {
if (c.isFocused()) {
return true;
}
if (c instanceof Parent) {
boolean internalFocus = isFocusInside((Parent) c);
if (internalFocus) {
return true;
}
}
}
return false;
}
- duplicates
-
JDK-8268225 Support :focus-visible and :focus-within CSS pseudoclasses
- Resolved