Example usage for javax.accessibility AccessibleContext setAccessibleName

List of usage examples for javax.accessibility AccessibleContext setAccessibleName

Introduction

In this page you can find the example usage for javax.accessibility AccessibleContext setAccessibleName.

Prototype

@BeanProperty(preferred = true, description = "Sets the accessible name for the component.")
public void setAccessibleName(String s) 

Source Link

Document

Sets the localized accessible name of this object.

Usage

From source file:Main.java

public static <T extends Component> T setAccessibleContext(T comp, String name) {
    if (comp == null)
        return comp;
    AccessibleContext ac = comp.getAccessibleContext();
    if (ac == null)
        return comp;
    String text = null;//from  w w w  .java2 s.  com
    if (name != null && !name.isEmpty())
        text = name;
    else if (comp instanceof AbstractButton)
        text = ((AbstractButton) comp).getText();
    else
        text = comp.getName();
    if (text != null) {
        ac.setAccessibleName(text);
        ac.setAccessibleDescription(text);
    }
    return comp;
}

From source file:MainClass.java

MainClass(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    AccessibleContext ac = getAccessibleContext();
    ac.setAccessibleDescription("Accessibility Demo1 description.");

    ac = getRootPane().getAccessibleContext();
    ac.setAccessibleName("Root pane");
    ac.setAccessibleDescription("Root pane description");

    ac = getGlassPane().getAccessibleContext();
    ac.setAccessibleName("Glass pane");
    ac.setAccessibleDescription("Glass pane description");

    ac = getLayeredPane().getAccessibleContext();
    ac.setAccessibleName("Layered pane");
    ac.setAccessibleDescription("Layered pane description");

    ac = getContentPane().getAccessibleContext();
    ac.setAccessibleName("Content pane");
    ac.setAccessibleDescription("Content pane description");

    JPanel p = new JPanel();
    ac = p.getAccessibleContext();//from   w  ww .  j a  va  2  s  .c o m
    ac.setAccessibleName("Panel");
    ac.setAccessibleDescription("Panel description");

    jb = new JButton("Press Me");
    jb.addActionListener(this);
    jb.setToolTipText("Press me for accessibility information.");
    p.add(jb);

    getContentPane().add(p);

    setSize(200, 75);
    setVisible(true);
}