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

viewToModel returns null bias sometimes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • None
    • 6
    • client-libs
    • Cause Known
    • generic
    • generic

      - Compile and run the following test case.
      - Move the mouse over the JEditorPane and it will print out the result of viewToModel for the point under the mouse.
      - Notice that the bias it returns for locations in the top inset is null.

      This is an unexpected return value for the bias. It caused problems with DnD code that didn't expect null. It's been worked around (see 6456844) in the DnD code for now, but should be fixed.

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.text.*;
      import javax.swing.border.*;

      public class V2MTest extends JFrame {
          
          public V2MTest() {
              super("V2MTest");
              
              final JEditorPane ep = new JEditorPane();
              ep.setContentType("text/html");
              ep.setText("a\nb\nc");
              ep.setBorder(new EmptyBorder(20, 20, 20, 20));
              getContentPane().add(ep);
              
              ep.addMouseMotionListener(new MouseMotionAdapter() {
                  public void mouseMoved(MouseEvent me) {
                      Position.Bias[] bias = new Position.Bias[1];
                      int index = ep.getUI().viewToModel(ep, me.getPoint(), bias);
                      System.out.println(index + ", " + bias[0]);
                  }
              });
          }

          private static void createAndShowGUI(String[] args) {
              V2MTest test = new V2MTest();
              test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              test.setSize(400, 400);
              test.setLocationRelativeTo(null);
              test.setVisible(true);
          }
          
          public static void main(final String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      createAndShowGUI(args);
                  }
              });
          }
      }

            peterz Peter Zhelezniakov
            shickeysunw Shannon Hickey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: