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

AccessibleJLabel getCharacterBounds() and getIndexAtPoint() methods throw NPE

    Details

    • Subcomponent:
    • Resolved In Build:
      kestrel
    • CPU:
      sparc
    • OS:
      solaris_2.6
    • Verification:
      Not verified

      Description



      Name: aaC67449 Date: 10/04/99


      AccessibleJLabel 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.JLabel;
      import javax.accessibility.AccessibleText;

      public class Test{

          public static void main(String argv[]) {
              JLabel o = new JLabel("<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.JLabel$AccessibleJLabel.getTextRectangle(JLabel.java:1376)
              at javax.swing.JLabel$AccessibleJLabel.getIndexAtPoint(JLabel.java:1045)
              at Test.main(Test.java:9)


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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: