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






JFrame: getAccessibleContext()

  
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.accessibility.AccessibleContext;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainClass extends JFrame implements ActionListener {
  JButton jb;

  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();
    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);
  }

  public void actionPerformed(ActionEvent e) {
    dumpInfo(getAccessibleContext());
  }

  void dumpInfo(AccessibleContext ac) {
    System.out.println("Name = " + ac.getAccessibleName());
    System.out.println("Description = " + ac.getAccessibleDescription());

    int nChildren = ac.getAccessibleChildrenCount();

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

  public static void main(String[] args) {
    new MainClass("Accessibility Demo1");
  }
}

           
         
    
  








Related examples in the same category

1.JFrame.DISPOSE_ON_CLOSE
2.JFrame.DO_NOTHING_ON_CLOSE
3.JFrame.EXIT_ON_CLOSE
4.JFrame: addComponentListener(ComponentListener l)
5.JFrame: addContainerListener(ContainerListener l)1
6.JFrame: addMouseWheelListener(MouseWheelListener l)
7.JFrame: addWindowListener(WindowListener lis)
8.JFrame: getContentPane().getActionMap() [Bind key action to JFrame]
9.JFrame: getDefaultCloseOperation()
10.JFrame: getFontMetrics(Font font)
11.JFrame: getGlassPane()
12.JFrame: getLayeredPane()
13.JFrame: isFocusOwner()
14.JFrame: isUndecorated()
15.JFrame: processWindowEvent(WindowEvent e)
16.JFrame: setAlwaysOnTop(boolean alwaysOnTop)
17.JFrame: setBackground(Color c)
18.JFrame: setCursor(Cursor c)
19.JFrame: setDefaultButton(JButton defaultButton)
20.JFrame: setDefaultButton(JButton bn) (Remove 'Enter' key stroke from JTextField)
21.JFrame: setDefaultCloseOperation(int option)
22.JFrame: setDefaultLookAndFeelDecorated(boolean b)
23.JFrame: setExtendedState(int state)
24.JFrame: setFocusable(boolean focusable)
25.JFrame: setFocusableWindowState(boolean focusableWindowState)
26.JFrame: setFocusTraversalPolicy(FocusTraversalPolicy lo)
27.JFrame: setIconImage(Image image)
28.JFrame: setJMenuBar(JMenuBar bar)
29.JFrame: setLocation(int x, int y)
30.JFrame: setLocationByPlatform(boolean locationByPlatform)
31.JFrame: setLocationRelativeTo(Component c)
32.JFrame: setMaximizedBounds(Rectangle bounds)
33.JFrame: setSize(int width, int height)
34.JFrame: setTitle(String title)
35.JFrame: setUndecorated(boolean b)
36.JFrame: setVisible(boolean visible)