AccessibleContext: getAccessibleText() : AccessibleContext « javax.accessibility « Java by API






AccessibleContext: getAccessibleText()

import java.awt.Dimension;

import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleText;
import javax.swing.JFrame;
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));
    JTextField jtf = new JTextField(20);
    jtf.setPreferredSize(new Dimension(100, 20));
    p.add(jtf);

    getContentPane().add(p);

    pack();
    setVisible(true);
  }

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

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

    ad8.dumpTextInfo(ad8.getAccessibleContext());
  }

  void dumpTextInfo(AccessibleContext ac) {
    AccessibleText at = ac.getAccessibleText();

    if (at != null) {
      System.out.println("Caret position = " + at.getCaretPosition());
      System.out.println("Selected text = " + at.getSelectedText());

      return;
    }

    int nChildren = ac.getAccessibleChildrenCount();

    for (int i = 0; i < nChildren; i++)
      dumpTextInfo(ac.getAccessibleChild(i).getAccessibleContext());
  }
}

           
       








Related examples in the same category

1.AccessibleContext: getAccessibleAction()
2.AccessibleAction: getAccessibleActionCount()
3.AccessibleContext: getAccessibleChildrenCount()
4.AccessibleContext: getAccessibleDescription()
5.AccessibleContext: getAccessibleName()
6.AccessibleContext: getAccessibleRelationSet()
7.AccessibleContext: getAccessibleSelection()
8.AccessibleContext: getAccessibleTable()
9.AccessibleContext: getAccessibleValue()
10.AccessibleContext: setAccessibleDescription(String s)
11.AccessibleContext: setAccessibleName(String s)