JComponent: getAccessibleContext() : JComponent « javax.swing « Java by API






JComponent: getAccessibleContext()

  
import java.awt.Dimension;

import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRelation;
import javax.accessibility.AccessibleRelationSet;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MainClass extends JFrame {
  
  MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(300, 50));
    JLabel jl = new JLabel("Name:");
    p.add(jl);
    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);
  }

  public static void main(String[] args) {
    MainClass ad11 = new MainClass();

    try {
      Thread.sleep(5000);
    } catch (InterruptedException e) {
    }

    ad11.dumpConnectedInfo(ad11.getAccessibleContext());
  }

  void dumpConnectedInfo(AccessibleContext ac) {
    AccessibleRelationSet ars = ac.getAccessibleRelationSet();

    AccessibleRelation ar = null;

    if (ars != null)
      ar = ars.get("connector");

    if (ar != null) {
      Object[] o = ar.getTarget();
      JComponent jc = (JComponent) o[0];
      System.out.println("Label connected to: " + jc.getAccessibleContext().getAccessibleName());
      return;
    }
    int nChildren = ac.getAccessibleChildrenCount();
    for (int i = 0; i < nChildren; i++)
      dumpConnectedInfo(ac.getAccessibleChild(i).getAccessibleContext());
  }
}

           
         
    
  








Related examples in the same category

1.JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
2.JComponent.WHEN_IN_FOCUSED_WINDOW
3.JComponent: addPropertyChangeListener(PropertyChangeListener listener)
4.JComponent: addVetoableChangeListener(VetoableChangeListener listener)
5.JComponent: getActionMap()
6.JComponent: getHeight()
7.JComponent: getInputMap()
8.JComponent: getTransferHandler()
9.JComponent: getWidth()
10.JComponent: getX()
11.JComponent: getY()
12.JComponent: putClientProperty(Object key, Object value)
13.JComponent: requestFocusInWindow()
14.JComponent: registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition)
15.JComponent: revalidate()
16.JComponent: setComponentPopupMenu(JPopupMenu popup)
17.JComponent: setFont(Font font)
18.JComponent: setFocusTraversalKeys(int arg0, Set arg1)
19.JComponent: setInputMap(int condition, InputMap map)
20.JComponent: setInputVerifier(InputVerifier inputVerifier)
21.JComponent: setOpaque(boolean isOpaque)
22.JComponent: setTransferHandler(TransferHandler newHandler)