AccessibleSelection: getAccessibleSelection(int i) : AccessibleSelection « javax.accessibility « Java by API






AccessibleSelection: getAccessibleSelection(int i)

import java.awt.Dimension;
import java.util.Vector;

import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleSelection;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class MainClass extends JFrame {
  MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector v = new Vector();
    v.add("First item");
    v.add("Second item");
    v.add("Third item");
    v.add("Fourth item");

    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(200, 100));
    JList jl = new JList(v);
    jl.setPreferredSize(new Dimension(100, 75));
    p.add(new JScrollPane(jl));

    getContentPane().add(p);

    pack();
    setVisible(true);
  }

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

    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    ad6.dumpSelectionInfo(ad6.getAccessibleContext());
  }

  void dumpSelectionInfo(AccessibleContext ac) {
    AccessibleSelection as = ac.getAccessibleSelection();
    if (as != null) {
      int count = as.getAccessibleSelectionCount();

      for (int i = 0; i < count; i++) {
        Accessible a = as.getAccessibleSelection(i);
        AccessibleContext ac2 = a.getAccessibleContext();
        String s = ac2.getAccessibleName();
        System.out.println("Name = " + s);
      }

      return;
    }

    int nChildren = ac.getAccessibleChildrenCount();

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

           
       








Related examples in the same category