-
Bug
-
Resolution: Incomplete
-
P4
-
None
-
8u401
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
When the popup with Button as node is closed, the UI-focus is correctly moved while the Accessibility-focus remains in the wrong place. But even attempting to move the focus explicitely with node.requestFocus() works if node is a TextField, but does not work if node is a Button. I attached a test code to reproduce.
---------- BEGIN SOURCE ----------
package fxbugs;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.AccessibleAction;
import javafx.scene.AccessibleAttribute;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PopupControl;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
* A simple application to demonstrate that when a popupcontrol is hidden, it
* still retains the focus.
*/
public class PopupControlRetainsFocus extends Application {
@Override
public void start( Stage primaryStage ) throws Exception {
VBox root = new VBox(30);
root.setPadding( new Insets(30) );
Button bPopup = new Button("popup");
TextField textField = new TextField();
root.getChildren().addAll( textField, bPopup );
bPopup.setOnAction( evt -> {
PopupControl popup = new PopupControl();
TextField popupTF = new TextField( textField.getText() );
final StackPane popupRoot = new StackPane( popupTF );
popupRoot.setBackground( new Background( new BackgroundFill( Color.ALICEBLUE, CornerRadii.EMPTY, Insets.EMPTY ) ) );
popupRoot.setPadding( new Insets( 50 ) );
popup.getScene().setRoot( popupRoot );
popup.show(primaryStage);
popup.addEventFilter( KeyEvent.KEY_PRESSED, keyEvt -> {
if( KeyCode.ESCAPE.equals( keyEvt.getCode() ) ) {
popup.hide();
textField.setText( popupTF.getText() );
/*
* If we request focus on the Button, it will not work;
* ...but if we request focus on the TextField, it will.
*/
// bPopup.requestFocus();
/*
* ...regardless of how we do it: the following is equivalent to the simple "requestFocus()" above
*
* bPopup.executeAccessibleAction(AccessibleAction.REQUEST_FOCUS)
*/
/*
* but THE FOLLOWING WORKS! (can be called on root or on bPopup, or actually even on textField)
*/
root.notifyAccessibleAttributeChanged(AccessibleAttribute.FOCUS_NODE);
}
} );
} );
primaryStage.setScene( new Scene( root, 800, 800 ) );
primaryStage.show();
}
public static void main( String[] args ) {
launch( args );
}
}
---------- END SOURCE ----------
FREQUENCY : always
When the popup with Button as node is closed, the UI-focus is correctly moved while the Accessibility-focus remains in the wrong place. But even attempting to move the focus explicitely with node.requestFocus() works if node is a TextField, but does not work if node is a Button. I attached a test code to reproduce.
---------- BEGIN SOURCE ----------
package fxbugs;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.AccessibleAction;
import javafx.scene.AccessibleAttribute;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PopupControl;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
* A simple application to demonstrate that when a popupcontrol is hidden, it
* still retains the focus.
*/
public class PopupControlRetainsFocus extends Application {
@Override
public void start( Stage primaryStage ) throws Exception {
VBox root = new VBox(30);
root.setPadding( new Insets(30) );
Button bPopup = new Button("popup");
TextField textField = new TextField();
root.getChildren().addAll( textField, bPopup );
bPopup.setOnAction( evt -> {
PopupControl popup = new PopupControl();
TextField popupTF = new TextField( textField.getText() );
final StackPane popupRoot = new StackPane( popupTF );
popupRoot.setBackground( new Background( new BackgroundFill( Color.ALICEBLUE, CornerRadii.EMPTY, Insets.EMPTY ) ) );
popupRoot.setPadding( new Insets( 50 ) );
popup.getScene().setRoot( popupRoot );
popup.show(primaryStage);
popup.addEventFilter( KeyEvent.KEY_PRESSED, keyEvt -> {
if( KeyCode.ESCAPE.equals( keyEvt.getCode() ) ) {
popup.hide();
textField.setText( popupTF.getText() );
/*
* If we request focus on the Button, it will not work;
* ...but if we request focus on the TextField, it will.
*/
// bPopup.requestFocus();
/*
* ...regardless of how we do it: the following is equivalent to the simple "requestFocus()" above
*
* bPopup.executeAccessibleAction(AccessibleAction.REQUEST_FOCUS)
*/
/*
* but THE FOLLOWING WORKS! (can be called on root or on bPopup, or actually even on textField)
*/
root.notifyAccessibleAttributeChanged(AccessibleAttribute.FOCUS_NODE);
}
} );
} );
primaryStage.setScene( new Scene( root, 800, 800 ) );
primaryStage.show();
}
public static void main( String[] args ) {
launch( args );
}
}
---------- END SOURCE ----------
FREQUENCY : always