Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4277820

AccessibleAbstractButton getCharacterBounds() and getIndexAtPoint() throw NPE

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.6
    • Not verified



      Name: aaC67449 Date: 10/04/99


      AccessibleAbstractButton getCharacterBounds() and getIndexAtPoint() methods throw
      NullPointerException, but should simply return null and -1.

      See javadoc:"
      public int getIndexAtPoint(Point p)

            Given a point in local coordinates, return the zero-based index of the character
            under that Point. If the point is invalid, this method returns -1.
            Specified by:
                  getIndexAtPoint in interface AccessibleText
            Parameters:
                  p - the Point in local coordinates
            Returns:
                  the zero-based index of the character under Point p; if Point is invalid returns
                  -1.

      ublic Rectangle getCharacterBounds(int i)

            Determine the bounding box of the character at the given index into the string. The
            bounds are returned in local coordinates. If the index is invalid an empty rectangle
            is returned.
            Specified by:
                  getCharacterBounds in interface AccessibleText
            Parameters:
                  i - the index into the String
            Returns:
                  the screen coordinates of the character's the bounding box, if index is invalid
                  returns an empty rectangle.
      "


      See example:
      ------------------------- example ----------------
      import javax.swing.JButton;
      import javax.accessibility.AccessibleText;

      public class Test{

          public static void main(String argv[]) {
              JButton o = new JButton("<html><body><p>Test</p></body></html>");
              AccessibleText c = o.getAccessibleContext().getAccessibleText();
              c.getIndexAtPoint(new java.awt.Point(0,0));
              System.out.println("Ok");
          }

      }
      -------------------- output -------------------
      Exception in thread "main" java.lang.NullPointerException
              at javax.swing.AbstractButton$AccessibleAbstractButton.getTextRectangle(AbstractButton.java:2056)
              at javax.swing.AbstractButton$AccessibleAbstractButton.getIndexAtPoint(AbstractButton.java:1725)
              at Test.main(Test.java:9)

      ======================================================================

            pkorn Peter Korn (Inactive)
            alisunw Ali Ali (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: