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

Changing selection with arrows causes scrolling

    XMLWordPrintable

Details

    • kestrel
    • generic
    • generic

    Description



      Name: skT88420 Date: 09/10/99


      /*
      To reproduce this bug:
      1) Select the "dan" node
      2) Open the "dan" node
      3) Scroll to the right a little
      4) Select the "xyz" node by using the down arrow (NOT the mouse).
      The scroll window will jump all the way back to the far left.
      This only happens when changing the selection with the keyboard.
      Changing it with the mouse or changing it programmatically (try using
      the "next" button) does not cause it to happen.
      This happens with JDK 1.2.2 and 1.3beta on Solaris.
      How can I stop it from scrolling?
      */
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.tree.*;

      public class Test9 {
          static public void main(String argv[]) throws Exception {
      DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
      String[] lev1 = { "foo", "bar", "dan" };
      String[][] lev2 = {
      { },
      { "small", "a nice big node for testing" },
      { "xyz", "pqd", "a really really big node for testing" } };
      for (int i=0; i<lev1.length; i++) {
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(lev1[i]);
      root.add(child);
      String[] sa = lev2[i];
      for (int j=0; j<lev2[i].length; j++)
      child.add(new DefaultMutableTreeNode(lev2[i][j]));
      }
      final JTree tree = new JTree(root);
      final JFrame frame = new JFrame("Test");
      frame.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
      JButton b = new JButton("next");
      b.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent event) {
      int row = tree.getMaxSelectionRow();
      tree.setSelectionRow(row+1);
      }
      });
      frame.getContentPane().add(b, BorderLayout.SOUTH);
      frame.setSize(200, 200);
      frame.setVisible(true);
      frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent event) {
      System.exit(0);
      }
      });
          }
      }
      (Review ID: 95081)
      ======================================================================

      Attachments

        Activity

          People

            svioletsunw Scott Violet (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: