Screen reader won't read the JavaFX UI when it is integrated into a Swing Application. I am using JAWS to test the accessibility.
I tried enabling java accessibility bridge but it did not work. When the java accessibility bridge is enabled screen reader will read the frame head but not the content.
import static javafx.geometry.HPos.RIGHT;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class LoginSwingFX extends JFrame
{
private final JFXPanel jfxPanel = new JFXPanel();
private LoginSwingFX()
{
super();
initComponents();
}
private void initComponents()
{
setTitle("Java Swing Welcome");
createScene();
getContentPane().add(jfxPanel);
setPreferredSize(new Dimension(1024, 600));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}
private void createScene()
{
Platform.runLater(() -> {
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Text sceneTitle = new Text("Welcome");
sceneTitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
grid.add(sceneTitle, 0, 0, 2, 1);
Label userName = new Label("User Name:");
grid.add(userName, 0, 1);
TextField userTextField = new TextField();
grid.add(userTextField, 1, 1);
userName.setLabelFor(userTextField);
Label pw = new Label("Password:");
grid.add(pw, 0, 2);
PasswordField pwBox = new PasswordField();
grid.add(pwBox, 1, 2);
pw.setLabelFor(pwBox);
Button btn = new Button("Sign in");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
hbBtn.getChildren().add(btn);
grid.add(hbBtn, 1, 4);
final Text actionTarget = new Text();
grid.add(actionTarget, 0, 6);
GridPane.setColumnSpan(actionTarget, 2);
GridPane.setHalignment(actionTarget, RIGHT);
actionTarget.setId("actionTarget");
btn.setOnAction(e -> {
actionTarget.setFill(Color.FIREBRICK);
actionTarget.setText("Sign in button pressed");
});
jfxPanel.setScene(new Scene(grid, 300, 275));
});
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(() -> {
LoginSwingFX loginSwingFX = new LoginSwingFX();
loginSwingFX.setVisible(true);
});
}
}
I am using jdk1.8u152.