当将JavaFX UI集成到Swing应用程序中时,屏幕阅读器将无法读取。我正在使用JAWS来测试可访问性。
我已经使用了来自oracle教程的login example并进行了可访问性测试,并且可以正常工作。但是,当我对其进行编辑并将JavaFX UI集成到JFrame中时,它将停止工作。
我尝试启用Java可访问性桥,但是它不起作用。启用Java辅助功能桥后,屏幕阅读器将读取框架头,但不读取内容。
下面您可以找到我编写的示例代码,
import static javafx.geometry.HPos.RIGHT;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
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 final JPanel panel = new JPanel(new BorderLayout());
private LoginSwingFX()
{
super();
initComponents();
}
private void initComponents()
{
setTitle("Java Swing Welcome");
createScene();
panel.add(jfxPanel, BorderLayout.CENTER);
getContentPane().add(panel);
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);
});
}