problem with making accessible GUI in Java
Hello everyone,
So I am trying to make a program with Java and I am at the stage of designing the GUI, so I decided to test using the swing library. I made a simple testing project for checking how to use swing to make accessible GUI.
Right now I am somewhat stuck, so I was hoping someone with swing experience could give me some advice.
My test program isn’t accessible. All that it does is make a window with a single button. When the button is pressed, a simple message is printed to console. The problem is that when the window opens up i can navigate over to the window, but it claims the window has no objects and unknown focus. \even though the window clearly contains a button and even the system focus is on the button, since when I press spacebar, it fires off an Action event.
I will provide source code for theis test class at the end of the post.
If there is someone with experience with this, could they please let me know what I need to do to allow the screen reader to be able to read the information in the swing GUI.
By the way, I do have java access bridge enabled.
Source code:
package test;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/**
* Testing class. Creates window with a single button.
*/
public class TestWindow extends JFrame implements ActionListener {
// test button
private JButton button;
public TestWindow() {
// basic window properties
super("test window");
setLocationByPlatform(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// try to set look and feel to system look and feel
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
// set up button
button = new JButton("Press me");
// add the TestWindow as action listener
button.addActionListener(this);
// layout button on window
getContentPane().setLayout(new BorderLayout());
getContentPane().add(button, BorderLayout.CENTER);
pack();
// make window visible
setVisible(true);
// set focus to button
button.requestFocus();
}
@Override
public void actionPerformed(ActionEvent e) {
// when button is pressed, print message to console
System.out.println("I was pressed!");
}
// end of class
}
_______________________________________________ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector