Example usage for javax.swing JLabel getAccessibleContext

List of usage examples for javax.swing JLabel getAccessibleContext

Introduction

In this page you can find the example usage for javax.swing JLabel getAccessibleContext.

Prototype

@BeanProperty(bound = false, expert = true, description = "The AccessibleContext associated with this Label.")
public AccessibleContext getAccessibleContext() 

Source Link

Document

Get the AccessibleContext of this object

Usage

From source file:MainClass.java

MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(300, 50));
    JLabel jl = new JLabel("Name:");
    p.add(jl);/*  w  w w .  j a va  2 s . com*/
    JTextField jtf = new JTextField(20);
    jtf.getAccessibleContext().setAccessibleName("Name-entry");
    p.add(jtf);

    AccessibleRelation ar = new AccessibleRelation("connector", jtf);

    AccessibleContext ac = jl.getAccessibleContext();
    ac.getAccessibleRelationSet().add(ar);

    getContentPane().add(p);

    pack();
    setVisible(true);
}

From source file:org.swiftexplorer.gui.AboutDlg.java

public static void show(Component parent, HasLocalizedStrings stringsBundle) {
    URI uri = null;/*  ww  w .j av  a  2 s.  c om*/
    try {
        uri = new URI("http://www.swiftexplorer.org");
    } catch (URISyntaxException e) {
        logger.error("URL seems to be ill-formed", e);
    }
    final String buttontext = "www.swiftexplorer.org";

    Box mainBox = Box.createVerticalBox();
    mainBox.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));

    StringBuilder sb = loadResource("/about.html");
    JLabel label = new JLabel(sb.toString());
    label.getAccessibleContext().setAccessibleDescription(getTitle(stringsBundle));
    mainBox.add(label);

    if (uri != null) {
        JButton button = new JButton();
        button.setText(buttontext);
        button.setToolTipText(uri.toString());
        button.addActionListener(new OpenUrlAction(uri));
        FontMetrics metrics = button.getFontMetrics(button.getFont());
        if (metrics != null)
            button.setSize(metrics.stringWidth(buttontext), button.getHeight());
        button.getAccessibleContext().setAccessibleDescription(buttontext);
        mainBox.add(button);
    }

    mainBox.add(Box.createVerticalStrut(10));

    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    panel.add(mainBox);

    JOptionPane.showMessageDialog(parent, panel, getTitle(stringsBundle), JOptionPane.INFORMATION_MESSAGE,
            getIcon());
}