Skip to Page Content | Navigation for Module


Navigation for Module 10: Scripts/Java
Page 13 of 19

ToolTips in Java

Swing components have the ability to set tool tips - or text that appears when the mouse hovers above the component. When using tool tips from an accessibility standpoint, if a description was not set (see Image 5), use setAccessibleDescription( ). Then, the accessibility model will use the tool tip text as a substitution. This is another example of how creating accessible applications can benefit all users.


Image 5: Tool Tip without description set

Code example of setting tool tip description

import javax.swing.*;
 
class ToolTipTest extends JFrame {
   JButton button1;
 
   ToolTipTest() {
      super ("ToolTip Test");
      button1 = new JButton("Button 2");
      button1.setToolTipText("The Electric Shock Button");
      this.getContentPane().add(button1);
      this.setSize(200,75);
      this.setVisible(true);
   }
 
   public static void main (String args[]) {
      ToolTipTest ttt = new ToolTipTest();
   }
}

The next page will discuss the mnemonics and accelerators.

Top of Page arrow up
       Page 13


 
-- END OF PAGE