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

Very first drag-copy of a JTable Selection causes the Selection to grow

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.4.1
    • client-libs

    Description



      Name: jk109818 Date: 09/16/2002


      FULL PRODUCT VERSION :
      java version "1.4.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
      Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

      AND

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

      FULL OPERATING SYSTEM VERSION :
      Windows 98 [Version 4.10.2222]


      A DESCRIPTION OF THE PROBLEM :
      There appears to be a timing problem in activating the drag
      mechanism. The very first drag attempt of a selection in a
      JTable trigger a "drag not allowed" icon and the selection
      to grow a few rows and/or columns, then the drag-copy icon
      appears. This problem doesn't manifest itself in
      subsequent attempt in the same sessin. The problem also
      doesn't manifest itself if one start the drag by pressing
      the left button of the mouse and move the mouse within the
      section for a little while before moving the mouse out of
      the selection to the drop location.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. activate the compiled program
      2. make a selection
      3. press the left mouse button in any cell inside the
      selection and drag to a cell several rows and/or columns
      outside of the range and wait for the selection to grow
      4. repeat steps 2 and 3 and the selection remain intact
      5. exit the program and repeat steps 1 thru 3

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The expected result is for the selection to remain the same
      during the DnD operation.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      AOKabc.java
      ===========
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.table.*;
      import java.text.*;

      public class AOKabc extends JApplet {
         static myMenu window;
         public void init() {
            initialize();
            window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
         }
         public void stop() {
            window.dispose();
         }
         public static void main(String[] args) {
            initialize();
            window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
         }
         private static void initialize() {
            window = new myMenu("AOKabc");
            window.setVisible(true);
         }
         static class myMenu extends JFrame {
            JScrollPane scrollPane;
            public myTable myTbl;
            JFrame frame=new JFrame();
            JPanel panel=new JPanel(new BorderLayout());
            public myMenu(String title) {
               super(title);
               setSize(800,600);
               Container contentPane = getContentPane();
               myTbl=new myTable(800,600);
               scrollPane=new JScrollPane(myTbl);
               panel.add("Center",scrollPane);
               contentPane.add(panel,BorderLayout.CENTER);
            }
         }
      }


      myTable.java
      ============
      import javax.swing.*;
      import javax.swing.table.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import java.text.*;
      import java.awt.dnd.*;
      import java.awt.datatransfer.*;

      public class myTable extends JTable implements DropTargetListener {
         public static final int maxCol=26;
         public static final int maxRow=100;
         Object rowData[][]=new Object[maxRow][maxCol];
         Rectangle drawRect;
         private DropTarget dropTarget;

         myTable(int width, int height) {
            setPreferredScrollableViewportSize(new Dimension(width,height));
            TableModel TM=new AbstractTableModel() {
               public Object getValueAt(int row, int col) {
                  if (rowData[row][col]==null) return "";
                  return rowData[row][col];
               }
               public int getColumnCount() {
                  return maxCol;
               }
               public int getRowCount() {
                  return maxRow;
               }
               public boolean isCellEditable(int row, int col) {
                  return true;
               }
               public void setValueAt(Object value, int row, int col) {
                  rowData[row][col]=value;
                  fireTableCellUpdated(row, col);
               }
            };
            setModel(TM);
            setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            setCellSelectionEnabled(true); // this basically turn off row
      selection highlighting
            getTableHeader().setReorderingAllowed(false);
            for (int i=0;i<maxCol;i++) getColumnModel().getColumn(i).setMinWidth(50);
            setDragEnabled(true);
            dropTarget=new DropTarget(this,this);
         }
         public void dropActionChanged(DropTargetDragEvent event) {}
         public void dragEnter(DropTargetDragEvent event) {}
         public void dragExit(DropTargetEvent event) {}
         public void dragOver(DropTargetDragEvent event) {}
         public void drop(DropTargetDropEvent event) {
            Transferable contents=event.getTransferable();
            if (contents!=null) {
               if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                  try {
                     Point p=event.getLocation();
                     int row=rowAtPoint(p);
                     int col=columnAtPoint(p);
                     String line=(String)contents.getTransferData
      (DataFlavor.stringFlavor);
                     int start=0;
                     int end=line.indexOf("\n");
                     if (end<0) {
                        setValueAt(line,row,col);
                        return;
                     }
                     String[] tmp;
                     while (end<=line.length()) {
                        tmp=getStringArray(line.substring(start,end),'\t');
                        for (int j=0;j<tmp.length;j++) setValueAt(tmp[j],row,col+j);
                        row++;
                        start=end+1;
                        if (start>=line.length()) break;
                        end=line.substring(start).indexOf("\n");
                        if (end>=0) end+=start; else end=line.length();
                     }
                  } catch (Throwable e) {
                     e.printStackTrace();
                  }
               }
            }
         }
         private String[] getStringArray(String inStr, char ctkn) {
            String[] x;
            if (inStr.length()==0) {
               x=new String[1];
               x[0]="";
               return x;
            }
            int i=0;
            String tmp="";
            ArrayList AL=new ArrayList(20);
            while (i<inStr.length()) {
               if (inStr.charAt(i)==ctkn) {
                  AL.add(new String(tmp));
                  tmp="";
               } else tmp+=inStr.charAt(i);
               i++;
            }
            AL.add(new String(tmp));
            x=new String[AL.size()];
            for (i=0;i<AL.size();i++) x[i]=(String)AL.get(i);
            return x;
         }
      }
      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Press and hold the left mouse button in the selection while
      moving the mouse around for a second or two before dragging
      to a droptarget.
      (Review ID: 163832)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              shickeysunw Shannon Hickey (Inactive)
              jkimsunw Jeffrey Kim (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: