JDK-4523910 : REGRESSION: setCaretPosition in JTextComponents not working in 1.4beta's
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2001-11-07
  • Updated: 2001-11-08
  • Resolved: 2001-11-08
Related Reports
Duplicate :  
Description

Name: ddT132432			Date: 11/06/2001


java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)


I submitted this bug months ago but did not receive a response, and I do not
see it listed so I will re-submit it.

Run the following code to see the bug:
--begin code--

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

class test{
  JTextPane jtp;
  
  test(){
    run();
  }
  
  void run(){
    JDialog jd=new JDialog();
    Container c=jd.getContentPane();
    c.setLayout(new BorderLayout(0,0));
    jtp=new JTextPane();
    Document d=jtp.getDocument();
    try{
      d.insertString(d.getLength(),"1\n2\n3\n4\n5\n6\n7\n8\n9\n10",null);
    }
    catch(Exception e){}
    JMenuBar jmb=new JMenuBar();
    JMenu jm=new JMenu("JMenu");
    JMenuItem jmi=new JMenuItem("JMenuItem");
    jm.add(jmi);
    jmb.add(jm);
    jmi.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
      	jtp.requestFocus();
        jtp.setCaretPosition(8);
      }
    });
    c.add(jmb,BorderLayout.NORTH);
    c.add(jtp,BorderLayout.CENTER);
    jd.pack();
    jd.setSize(200,300);
    jd.show();
  }
  
  public static void main(String[] args){
    test t=new test();
  }
  
}

--end code--

When run with JRE 1.4 beta (any beta), clicking on the "JMenuItem" button will
not set the text cursor correctly inside the JTextPane. When run with JRE
1.3.x, the program runs correctly - the text cursor is placed before the
number '5' when the JMenuItem button is clicked.

Release Regression From : merlin-rc1
The above release value was the last known release where this 
bug was knwon to work. Since then there has been a regression.

(Review ID: 135131) 
======================================================================

Comments
EVALUATION This is a result of the mouseClicked event being dispatched to the JTextPane. I believe Brent is working on this issue, which will hopefully fix this bug as well. ###@###.### 2001-11-07 This does indeed sound like a duplicate. I will run the test case once I have 4508327 fixed to make sure it fixes both bugs. ###@###.### 2001-11-07 I have confirmed that this is a duplicate of 4508327. ###@###.### 2001-11-07
07-11-2001