Dates in Jtable - tried and tried and tried

I have a table cell renderer to handle the date fields as follows.
The dates appear MM/dd/yyyy when the table is loaded as I want.
SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
if (((Vector)fieldInfo.elementAt(i)).elementAt(2).equals ("DATE")) {
      // set format for date display
     column = PassportTable.getColumnModel().getColumn(i);
     // Now get column renderer
     // and set cell renderer for column
     column.setCellRenderer(new DefaultTableCellRenderer() {
          public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row, int column) {
               Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                // Create and put formatted date in cell
               setText(cdnDate.format((java.util.Date)value));
               return renderer;
);The problem I have is I cannot get the date that appears as the user edits the field
in this format. I have got yyyy-MM-dd for example the cell shows "01/01/1900"
when the user starts to edit the field "1900-01-01" appears. I have managed
to make a variety of different formats appear but never the one I want.
I have tried the many variations of the following two methods to edit a date in a table cell.
Nothing I have tried has worked.
public void setUpDateEditor(JTable table) {
     //Set up the editor for the date cells.
     try {
          String str = "01/01/1900";
          java.util.Date passDate = cdnDate.parse(str);
          final LimitedDateField dateField = new LimitedDateField(passDate);
          DefaultCellEditor dateEditor = new DefaultCellEditor(dateField) {
               public Object getCellEditorValue() { // return a date
                    //return new java.util.Date(dateField.getValue()); //no compile
                    return dateField.getValue();
          table.setDefaultEditor(java.util.Date.class, dateEditor);
     catch (Exception showUpdatelEx) {}
Where my LimitedDateField class is as follows:public class LimitedDateField extends JTextField implements GlobalInterface {
     private Toolkit toolkit;
     private SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
     private char slaSign = '/';
     private int columnLimit;
     private java.util.Date retVal;
     public LimitedDateField(java.util.Date value) {
          //super(columns);
          columnLimit = 11;
          toolkit = Toolkit.getDefaultToolkit();
          setDocument(new DateDocument());
          setValue(value);
     public java.util.Date getValue() {
          String str = "01/01/1900";
          try {
               // retVal = cdnDate.parse(str);
               retVal = cdnDate.parse(getText());
          catch (ParseException e) {Toolkit.getDefaultToolkit().beep();}
          return retVal;
     public void setValue(java.util.Date value) {
          setText(cdnDate.format(value));
     protected class DateDocument extends PlainDocument {
          public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
               char[] source = str.toCharArray();               
               char[] result = new char[source.length];
               char[] hResult = new char[source.length]; // save
               int j = 0;
               if (super.getLength() > columnLimit - 1){toolkit.beep();}
               else {
                    for (int i = 0; i < result.length; i++) {
                         if (Character.isDigit(source)) {result[j++] = source[i];}
                         else if (source[i] == slaSign) {result[j++] = source[i];}
                         else {toolkit.beep();}
When this failed I tried something simpler - to no avail.
public void setUpDateEditor(JTable table) {
     //Set up the editor for the date cells.
     try {
          SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
          DateFormatter df = new DateFormatter(cdnDate);
          JFormattedTextField ftf1 = new JFormattedTextField(df);
     catch (Exception showUpdatelEx) {}Any suggestions????
Thanks
rykk

Try again as Format code missing
I have a table cell renderer to handle the date fields as follows.
The dates appear MM/dd/yyyy when the table is loaded as I want.
SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
if (((Vector)fieldInfo.elementAt(i)).elementAt(2).equals ("DATE")) {
      // set format for date display
     column = PassportTable.getColumnModel().getColumn(i);
     // Now get column renderer
     // and set cell renderer for column
     column.setCellRenderer(new DefaultTableCellRenderer() {
          public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
               Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                // Create and put formatted date in cell
               setText(cdnDate.format((java.util.Date)value));
               return renderer;
);The problem I have is I cannot get the date that appears as the user edits the field
in this format. I have got yyyy-MM-dd for example the cell shows "01/01/1900"
when the user starts to edit the field "1900-01-01" appears. I have managed
to make a variety of different formats appear but never the one I want.
I have tried the many variations of the following two methods to edit a date in a table cell.
Nothing I have tried has worked.
public void setUpDateEditor(JTable table) {
     //Set up the editor for the date cells.
     try {
          String str = "01/01/1900";
          java.util.Date passDate = cdnDate.parse(str);
          final LimitedDateField dateField = new LimitedDateField(passDate);
          DefaultCellEditor dateEditor = new DefaultCellEditor(dateField) {
               public Object getCellEditorValue() { // return a date
                    //return new java.util.Date(dateField.getValue()); //no compile
                    return dateField.getValue();
          table.setDefaultEditor(java.util.Date.class, dateEditor);
     catch (Exception showUpdatelEx) {}
}Where my LimitedDateField class is as follows:
public class LimitedDateField extends JTextField implements GlobalInterface {
     private Toolkit toolkit;
     private SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
     private char slaSign = '/';
     private int columnLimit;
     private java.util.Date retVal;
     public LimitedDateField(java.util.Date value) {
          //super(columns);
          columnLimit = 11;
          toolkit = Toolkit.getDefaultToolkit();
          setDocument(new DateDocument());
          setValue(value);
     public java.util.Date getValue() {
          String str = "01/01/1900";
          try {
               // retVal = cdnDate.parse(str);
               retVal = cdnDate.parse(getText());
          catch (ParseException e) {Toolkit.getDefaultToolkit().beep();}
          return retVal;
     public void setValue(java.util.Date value) {
          setText(cdnDate.format(value));
     protected class DateDocument extends PlainDocument {
          public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
               char[] source = str.toCharArray();               
               char[] result = new char[source.length];
               char[] hResult = new char[source.length]; // save
               int j = 0;
               if (super.getLength() > columnLimit - 1){toolkit.beep();}
               else {
                    for (int i = 0; i < result.length; i++) {
                         if (Character.isDigit(source)) {result[j++] = source[i];}
                         else if (source[i] == slaSign) {result[j++] = source[i];}
                         else {toolkit.beep();}
When this failed I tried something simpler - to no avail.
public void setUpDateEditor(JTable table) {
     //Set up the editor for the date cells.
     try {
          SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
          DateFormatter df = new DateFormatter(cdnDate);
          JFormattedTextField ftf1 = new JFormattedTextField(df);
     catch (Exception showUpdatelEx) {}Any suggestions????
Thanks
rykk

Similar Messages

  • I have had my IPAD2 for quite a while but haven't activated my cellular data for about a year.  I am now trying to activate and when I go to cellular data, turn it on and try to tap view account i just get a message that says "connection to server lost".

    I have had my IPAD2 for quite a while but haven't activated my cellular data for about a year.  I am now trying to activate and when I go to cellular data, turn it on and try to tap view account i just get a message that says "connection to server lost".  I could swear the last time I used cellular data you would see the signal in the upper left corner and I only see "no service" there, I am in a location where I know I should have service.  Is there something I should do to my IPAD?  I tried resetting, I tried clearing cookies and history in Safari (after reading a post n these discussions).  I don't know what to do next. My IOS version is 6.1.3.  I did go into Network from the general tab and I see it says "SIM not provisioned".    HELP and Thank you in advance.

    Hello Theresa818,
    Thank you for using Apple Support Communities!
    It sounds like the cellular data will not activate for some reason on the iPad.
    I found this article that will help you resolve this issue here, named iPad (Wi-Fi + Cellular Models): Troubleshooting a cellular data connection, found here http://support.apple.com/kb/TS4249
    Check for a carrier settings update.
    Update your iPad.
    Toggle the Cellular Data setting off and on under Settings > Cellular Data.
    Restart your iPad.
    Tap Settings > General > About. Locate the Carrier entry and make sure that your carrier is correct.
    If your SIM card has SIM PIN enabled, try turning it off: Tap Settings > Cellular Data > SIM PIN.
    Make sure you're in an area of good coverage. If the cellular data connection works in another area, contact your carrier to report the original affected area.
    Reset network settings: Tap Settings > General > Reset > Reset Network Settings.
    Restore the iPad as new.
    If none of the above steps resolves the issue, make an appointment at an Apple Retail Store, contact your carrier, or contact AppleCare to troubleshoot further.
    I know you may have done one or two of the steps here, so you can skip those.
    Take care,
    Sterling

  • I restored my phone on iTunes, but when I did, all my info deleted and now it's my sister's old data. I tried to go back on iTunes and restore, but my original data isn't even an option. How do I get my old data back?

    I restored my phone on iTunes, but when I did, all my info deleted and now it's my sister's old data. I tried to go back on iTunes and restore, but my original data isn't even an option. How do I get my old data back?

    Before you did the resotore Via itunes you should of made a Back-up of your Data. But to be honest, i don't think that you would be able to get that stuff back.. Sorry mate

  • I have an iphone 4s that i got last week and i set it up just using the phone. today my dad restored it as my mothers iphone so i lost all of my data. I tried to restore it as my original phone i had but i exited out of itunes and now my phone wont showup

    I have an iphone 4s that i got last week and i set it up just using the phone. today my dad restored it as my mothers iphone so i lost all of my data. I tried to restore it as my original phone i had but i exited out of itunes and now my phone wont showup in itunes or on my computer

    Did you fail to import them to your computer before restoring?
    Not good.
    They are likely gone.
    You can try restoring from backup.

  • I am using pages '09. I have been trying to put together a report and I am using tables to help keep my data in line. My data is free text and would like to footnote certain data as to it origin, but footnoting is grey-out. How can I footnote on table mod

    I am using pages '09. I have been trying to put together a report and I am using tables to help keep my data in line. My data is free text and would like to footnote certain data as to it origin, but footnoting is grey-out. How can I footnote in table mode inpages '09?

    Footnotes can only be inserted in the main text area between the margins on a Word Processing document.
    Peter

  • HT1386 Since 8th May , I am not able to synchronize my iPhone with iTunes. Have tried removing previous back up data , removed all photos and videos on iPhone , switched  on and of and  reset iPhone  a million times , restarted my Mac a thousand times :(

    Since 8th May , after updating the iphone software to 5.1.1  I am not able to synchronize my iPhone with iTunes. Have tried removing previous back up datas , removed all photos and videos on iPhone , switched  on and of and  reset iPhone  a million times , restarted my Mac a thousand times Please Help !!!

    I have tried both options .. back up on this computer and also back up on icloud.
    The backingup is fine .. there is no problem .. even synchronizing songs , applications , calender , mail accounts is fine .. only the contacs are not synchronizing. The itune goes on and on .. showing synchronizing contacs .. but nothing happens. When i uncheck contacts synchronisation .. everything works fine . I have also reorganized my address book . but it does not help

  • Hi I have iPhone 4 with iOS 6 and a week ago I stop ressiv or send SMS. I tried everything but I still can't send.. I erase the version and all the data on the iPhone and now I can send SMS. But when I'm downloading my buck up the problem happened againI'

    Hi I have iPhone 4 with iOS 6 and a week ago I stop ressiv or send SMS. I tried everything but I still can't send.. I erase the version and all the data on the iPhone and now I can send SMS. But when I'm downloading my buck up the problem happened again
    Please help me cuse I don't know what to do and my cellular company don't have an answer
    Thank u

    I have to ad that its not an easy problem I did all the action in the book.
    It's something with my back up

  • I tried to install up date 3.6.13 and received error message that I didn't have the right permissions on this mac book , but I am the administrator on my Mac Book Air? Any ideas how to resolve this?

    I tried to install up date 3.6.13 and received error message that I didn't have the system permissions required to install it. I am the administrator on my Mac Book Air? Any ideas how to resolve this?

    * Download a new copy of the Firefox program: http://www.mozilla.com/firefox/all.html
    * Trash the current Firefox application to do a clean (re)install.
    * Install the new version that you have downloaded.
    Your profile data is stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks and other personal data.

  • My iphone 5s got stolen and the option to erase data after 10 tries was not enabled. What happens after the incorrect password is input after 10 times?

    my iphone 5s got stolen and the option to erase data after 10 tries was not enabled. What happens after the incorrect password is input after 10 times?

    After the sixth erroneous passcode entry a delay is imposed that increases exponentially and eventually reaches over 40 years before another attempt can be made.
    No one yet knows how long the next delay is.

  • I can not pair my I hphone 6 with my iPad bot are op to date with soft wear and I have tried to reset the network of both of them with no success

    i can not pair my I phone 6 with my iPad bot are op to date with soft wear and I have tried to reset the network of both of them with no success

    Your iPhone's iOS must be same or newer than the one in backups. In your case it is older so you need to update your iPhone and then recover it with backup.

  • The computer says that my flash players is out of date, so I tried to update,   The download starts by stops at 25% and will not continue.

    the computer says that my flash players is out of date so I tried to update.  The download starts by stops at 25% and will not continue.

    Had the same problem (stalling at 25% or 30%).
    This worked for me:
    1.     Reboot computer or use Activity Monitor to force quit any prior Adobe Flash installation process that may be still running
    2.     Download Adobe Flash update using this link (assuming you are using Safari or Firefox): Flash Player for Safari and Firefox - NPAPI 
    3.     Mount flash player by clicking on flash drive icon on desktop
    4.     Right click on Flash file
    5.     Choose 'Show Package Contents'
    6.     Open 'Contents' then 'Resources'
    7.     Run file 'Adobe Flash Player.pkg'
    8.     Reboot computer.

  • App Store shows 9 updates but all Apps are up to date I have tried re downloading all the updates. All Apps show the correct version number post update.

    App Store shows that I have 9 updates but all Apps are up to date I have tried re downloading all the updates. All Apps show the correct version number post update.

    I have the same issue with one App in the App Store. The app is installed and current. But the App Store says I have an update. I tried restarting. No help.

  • HT4993 getting error message could not activate cellular data network when trying to access the internet without using wifi.  what do i need to do?  i have already restore the phone.

    getting error message could not activate cellular data network when trying to access the internet without using wifi.  what do i need to do?  i have already restore the phone.

    contact your phone carrier as they handle cellular network.

  • How to save data from JTable multiple rows and columns

    Hi Y_Not thanks for your help before...
    But what should I do if I want to get/save many data from many column and rows??

    i don't quite understand your (repeated) question. what is the problem with "multiple rows and columns". Y_NOT and i have shown you ways to access them.
    all you need are 2 loops: one around your number of rows and one around the number of columns or vice versa depending in which order you want to save things:
    for (int col = 0; col < data.size(); col++) {
        for (int row = 0 ; row < data[col].size(); row++) {
            // save your data
            saveData(data[col].getElementAt(row));
            // or use yourtable.getValueAt(row, col);
    }this is not a problem of Swing/Java but of simple algorithm...
    thomas

  • Must click then click and drag for JTable Drag and Drop

    Hi All,
    I've been using Java 1.4 to drag and drop data between two tables in our application. Basically I need to drag the data from individual rows of the source table and insert it into one of the cells in the new table. This works absolutely fine and has made a huge improvement to this portion of our app. I've included example source code below that does a similar thing by transferring data from one table and inserting it into another (it's quite big and also not as well done as the example in our real app but unfortunately I can't send the source for that).
    The thing I've noticed though is that in order to start dragging data I need to click to select it and then press and hold the mouse button to start dragging, whereas under W**dows and just about every other OS you can just press and hold and start dragging straight away. If you try this with a JTable though it just changes the rows you have selected so the drag and drop works but feels a bit clunky and amateurish. I'd like to do something about this such that it works like Windows Explorer (or similar) where you can just press the mouse button and start dragging.
    Any help would be greatly appreciated - and if anybody finds the code useful you're more than welcome to it. Note that the business end of this is CustomTransferHandler.java - this will show you how to insert data at a specific position in a JTable, it's a bit of a faff but not too bad once you've got it sussed.
    Thanks,
    Bart Read
    ===============================================================
    TestFrame.java
    * TestFrame.java
    * Created on October 21, 2002, 4:59 PM
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.dnd.*;
    import java.awt.event.*;
    import java.util.TooManyListenersException;
    import javax.swing.*;
    * @author  readb
    public class TestFrame extends javax.swing.JFrame
         private static final String [] NAMES     = {
              "John", "Geoff", "Madeleine", "Maria", "Flanders",
              "Homer", "Marge", "Bart", "Lisa", "Weird Baby" };
         private JTable source;
         private JTable dest;
         private MyTableModel     sourceModel;
         private MyTableModel     destModel;
         private Clipboard          clipboard;
         /** Creates a new instance of TestFrame */
         public TestFrame()
              clipboard = getToolkit().getSystemClipboard();
              Container c = getContentPane();
              c.setLayout( new BorderLayout( 40, 40 ) );
              source = new MyJTable();
              sourceModel = new MyTableModel();
              source.setModel( sourceModel );
              source.setDragEnabled( true );
              CustomTransferHandler handler = new CustomTransferHandler( "Source handler" );
              source.setTransferHandler( handler );
              try
                   source.getDropTarget().addDropTargetListener( handler );
              catch ( TooManyListenersException tmle )
                   tmle.printStackTrace();
              dest = new MyJTable();
              destModel = new MyTableModel();
              dest.setModel( destModel );
              dest.setDragEnabled( true );
              handler = new CustomTransferHandler( "Dest handler" );
              dest.setTransferHandler( handler );
              try
                   dest.getDropTarget().addDropTargetListener( handler );
              catch ( TooManyListenersException tmle )
                   tmle.printStackTrace();
              c.add( new JScrollPane( source ), BorderLayout.WEST );
              c.add( new JScrollPane( dest ), BorderLayout.EAST );
              populate();
         private void populate( MyTableModel model )
              for ( int index = 0; index < NAMES.length; ++index )
                   model.setRow( index, new DataRow( index + 1, NAMES[ index ] ) );
         private void populate()
              populate( sourceModel );
              populate( destModel );
         public static void main( String [] args )
              TestFrame app = new TestFrame();
              app.addWindowListener(
                   new WindowAdapter() {
                        public void windowClosing( WindowEvent we )
                             System.exit( 0 );
              app.pack();
              app.setSize( 1000, 600 );
              app.show();
         private class MyJTable extends JTable
              public boolean getScrollableTracksViewportHeight()
                   Component parent = getParent();
                   if (parent instanceof JViewport)
                        return parent.getHeight() > getPreferredSize().height;
                   return false;
    }=====================================================================
    MyTableModel.java
    * MyTableModel.java
    * Created on October 21, 2002, 4:43 PM
    import java.util.ArrayList;
    * @author  readb
    public class MyTableModel extends javax.swing.table.AbstractTableModel
         private static final int          NUMBER               = 0;
         private static final int          NAME               = 1;
         private static final String []     COLUMN_HEADINGS     = { "Number", "Name" };
         private ArrayList data;
         /** Creates a new instance of MyTableModel */
         public MyTableModel()
              super();
              data = new ArrayList();
         public int getColumnCount()
              return COLUMN_HEADINGS.length;
         public String getColumnName( int index )
              return COLUMN_HEADINGS[ index ];
         public Class getColumnClass( int index )
              switch ( index )
                   case NUMBER:
                        return Integer.class;
                   case NAME:
                        return String.class;
                   default:
                        throw new IllegalArgumentException( "Illegal column index: " + index );
         public int getRowCount()
              return ( null == data ? 0 : data.size() );
         public Object getValueAt( int row, int column )
              DataRow dataRow = ( DataRow ) data.get( row );
              switch ( column )
                   case NUMBER:
                        return new Integer( dataRow.getNumber() );
                   case NAME:
                        return dataRow.getName();
                   default:
                        throw new IllegalArgumentException( "Illegal column index: " + column );
         public void addRow( DataRow row )
              int rowIndex = data.size();
              data.add( row );
              fireTableRowsInserted( rowIndex, rowIndex );
         public void addRows( DataRow [] rows )
              int firstRow = data.size();
              for ( int index = 0; index < rows.length; ++index )
                   data.add( rows[ index ] );
              fireTableRowsInserted( firstRow, data.size() - 1 );
         public void setRow( int index, DataRow row )
              if ( index == data.size() )
                   data.add( row );
              else
                   data.set( index, row );
              fireTableRowsUpdated( index, index );
         public void insertRows( int index, DataRow [] rows )
              for ( int rowIndex = rows.length - 1; rowIndex >= 0; --rowIndex )
                   data.add( index, rows[ rowIndex ] );
              fireTableRowsInserted( index, index + rows.length - 1 );
         public DataRow getRow( int index )
              return ( DataRow ) data.get( index );
         public DataRow removeRow( int index )
              DataRow retVal = ( DataRow ) data.remove( index );
              fireTableRowsDeleted( index, index );
              return retVal;
         public boolean removeRow( DataRow row )
              int index = data.indexOf( row );
              boolean retVal = data.remove( row );
              fireTableRowsDeleted( index, index );
              return retVal;
         public void removeRows( DataRow [] rows )
              for ( int index = 0; index < rows.length; ++index )
                   data.remove( rows[ index ] );
              fireTableDataChanged();
    }=====================================================================
    DataRow.java
    * DataRow.java
    * Created on October 21, 2002, 4:41 PM
    import java.io.Serializable;
    * @author  readb
    public class DataRow implements Serializable
         private int          number;
         private String     name;
         /** Creates a new instance of DataRow */
         public DataRow( int number, String name )
              this.number = number;
              this.name = name;
         public int getNumber()
              return number;
         public String getName()
              return name;
         public String toString()
              return String.valueOf( number ) + ": " + name;
    }======================================================================
    CustomTransferHandler.java
    * CustomTransferHandler.java
    * Created on October 22, 2002, 8:36 AM
    import java.awt.*;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.ClipboardOwner;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.awt.dnd.*;
    import java.awt.event.InputEvent;
    import java.io.IOException;
    import java.util.Arrays;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JTable;
    import javax.swing.TransferHandler;
    * @author  readb
    public class CustomTransferHandler
                   extends TransferHandler
                   implements Transferable, ClipboardOwner, DropTargetListener
         public static final DataFlavor     ROW_ARRAY_FLAVOR     = new DataFlavor( DataRow[].class, "Multiple rows of data" );
         private String               name;
         private ImageIcon          myIcon;
         private     DataRow []          data;
         private boolean               clipboardOwner                    = false;
         private int                    rowIndex                         = -1;
         /** Creates a new instance of CustomTransferHandler */
         public CustomTransferHandler( String name )
              this.name = name;
         public boolean canImport( JComponent comp, DataFlavor [] transferFlavors )
              System.err.println( "CustomTransferHandler::canImport" );
              if ( comp instanceof JTable && ( ( JTable ) comp ).getModel() instanceof MyTableModel )
                   for ( int index = 0; index < transferFlavors.length; ++index )
                        if ( ! transferFlavors[ index ].equals( ROW_ARRAY_FLAVOR ) )
                             return false;
                   return true;
              else
                   return false;
         protected Transferable createTransferable( JComponent c )
              System.err.println( "CustomTransferHandler::createTransferable" );
              if ( ! ( c instanceof JTable ) || ! ( ( ( JTable ) c ).getModel() instanceof MyTableModel ) )
                   return null;
              this.data = null;
              JTable               table     = ( JTable ) c;
              MyTableModel     model     = ( MyTableModel ) table.getModel();
              Clipboard          cb          = table.getToolkit().getSystemClipboard();
              cb.setContents( this, this );
              clipboardOwner = true;
              int [] selectedRows = table.getSelectedRows();
              Arrays.sort( selectedRows );
              data = new DataRow[ selectedRows.length ];
              for ( int index = 0; index < data.length; ++index )
                   data[ index ] = model.getRow( selectedRows[ index ] );
              return this;
         public void exportAsDrag( JComponent comp, InputEvent e, int action )
              super.exportAsDrag( comp, e, action );
              Clipboard          cb          = comp.getToolkit().getSystemClipboard();
              cb.setContents( this, this );
         protected void exportDone( JComponent source, Transferable data, int action )
              System.err.println( "CustomTransferHandler::exportDone" );
              if ( TransferHandler.MOVE == action && source instanceof JTable && ( ( JTable ) source ).getModel() instanceof MyTableModel )
                   JTable table = ( JTable ) source;
                   MyTableModel model = ( MyTableModel ) table.getModel();
                   int [] selected = table.getSelectedRows();
                   for ( int index = selected.length - 1; index >= 0; --index )
                        model.removeRow( selected[ index ] );
         public void exportToClipboard( JComponent comp, Clipboard clip, int action )
              System.err.println( "CustomTransferHandler::exportToClipboard" );
         public int getSourceActions( JComponent c )
              System.err.println( "CustomTransferHandler::getSourceActions" );
              if ( ( c instanceof JTable ) && ( ( JTable ) c ).getModel() instanceof MyTableModel )
                   return MOVE;
              else
                   return NONE;
          *     I've commented this out because it doesn't appear to work in any case.
          *     The image isn't null but as far as I can tell this method is never
          *     invoked.
    //     public Icon getVisualRepresentation( Transferable t )
    //          System.err.println( "CustomTransferHandler::getVisualRepresentation" );
    //          if ( t instanceof CustomTransferHandler )
    //               if ( null == myIcon )
    //                    try
    //                         myIcon = new ImageIcon( getClass().getClassLoader().getResource( "dragimage.gif" ) );
    //                    catch ( Exception e )
    //                         System.err.println( "CustomTransferHandler::getVisualRepresentation: exception loading image" );
    //                         e.printStackTrace();
    //                    if ( null == myIcon )
    //                         System.err.println( "CustomTransferHandler::getVisualRepresentation: myIcon is still NULL" );
    //               return myIcon;
    //          else
    //               return null;
         public boolean importData( JComponent comp, Transferable t )
              System.err.println( "CustomTransferHandler::importData" );
              super.importData( comp, t );
              if ( ! ( comp instanceof JTable ) )
                   return false;
              if ( ! ( ( ( JTable ) comp ).getModel() instanceof MyTableModel ) )
                   return false;
              if ( clipboardOwner )
                   return false;
              if ( !t.isDataFlavorSupported( ROW_ARRAY_FLAVOR ) )
                   return false;
              try
                   data = ( DataRow [] ) t.getTransferData( ROW_ARRAY_FLAVOR );
                   return true;
              catch ( IOException ioe )
                   data = null;
                   return false;
              catch ( UnsupportedFlavorException ufe )
                   data = null;
                   return false;
         public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
              System.err.println( "MyTransferable::getTransferData" );
              if ( flavor.equals( ROW_ARRAY_FLAVOR ) )
                   return data;
              else
                   throw new UnsupportedFlavorException( flavor );
         public DataFlavor[] getTransferDataFlavors()
              System.err.println( "MyTransferable::getTransferDataFlavors" );
              DataFlavor [] flavors = new DataFlavor[ 1 ];
              flavors[ 0 ] = ROW_ARRAY_FLAVOR;
              return flavors;
         public boolean isDataFlavorSupported( DataFlavor flavor )
              System.err.println( "MyTransferable::isDataFlavorSupported" );
              return flavor.equals( ROW_ARRAY_FLAVOR );
         public void lostOwnership( Clipboard clipboard, Transferable transferable )
              clipboardOwner = false;
         /** Called while a drag operation is ongoing, when the mouse pointer enters
          * the operable part of the drop site for the <code>DropTarget</code>
          * registered with this listener.
          * @param dtde the <code>DropTargetDragEvent</code>
         public void dragEnter(DropTargetDragEvent dtde)
         /** Called while a drag operation is ongoing, when the mouse pointer has
          * exited the operable part of the drop site for the
          * <code>DropTarget</code> registered with this listener.
          * @param dte the <code>DropTargetEvent</code>
         public void dragExit(DropTargetEvent dte)
         /** Called when a drag operation is ongoing, while the mouse pointer is still
          * over the operable part of the drop site for the <code>DropTarget</code>
          * registered with this listener.
          * @param dtde the <code>DropTargetDragEvent</code>
         public void dragOver(DropTargetDragEvent dtde)
         /** Called when the drag operation has terminated with a drop on
          * the operable part of the drop site for the <code>DropTarget</code>
          * registered with this listener.
          * <p>
          * This method is responsible for undertaking
          * the transfer of the data associated with the
          * gesture. The <code>DropTargetDropEvent</code>
          * provides a means to obtain a <code>Transferable</code>
          * object that represents the data object(s) to
          * be transfered.<P>
          * From this method, the <code>DropTargetListener</code>
          * shall accept or reject the drop via the
          * acceptDrop(int dropAction) or rejectDrop() methods of the
          * <code>DropTargetDropEvent</code> parameter.
          * <P>
          * Subsequent to acceptDrop(), but not before,
          * <code>DropTargetDropEvent</code>'s getTransferable()
          * method may be invoked, and data transfer may be
          * performed via the returned <code>Transferable</code>'s
          * getTransferData() method.
          * <P>
          * At the completion of a drop, an implementation
          * of this method is required to signal the success/failure
          * of the drop by passing an appropriate
          * <code>boolean</code> to the <code>DropTargetDropEvent</code>'s
          * dropComplete(boolean success) method.
          * <P>
          * Note: The data transfer should be completed before the call  to the
          * <code>DropTargetDropEvent</code>'s dropComplete(boolean success) method.
          * After that, a call to the getTransferData() method of the
          * <code>Transferable</code> returned by
          * <code>DropTargetDropEvent.getTransferable()</code> is guaranteed to
          * succeed only if the data transfer is local; that is, only if
          * <code>DropTargetDropEvent.isLocalTransfer()</code> returns
          * <code>true</code>. Otherwise, the behavior of the call is
          * implementation-dependent.
          * <P>
          * @param dtde the <code>DropTargetDropEvent</code>
         public void drop(DropTargetDropEvent dtde)
              System.err.println( "CustomTransferHandler::drop" );
              Component c = dtde.getDropTargetContext().getDropTarget().getComponent();
              if ( ! ( c instanceof JComponent ) )
                   dtde.rejectDrop();
                   return;
              JComponent comp = ( JComponent ) c;
              if ( ! ( c instanceof JTable ) || ! ( ( ( JTable ) c ).getModel() instanceof MyTableModel ) )
                   dtde.rejectDrop();
                   return;
              dtde.acceptDrop( TransferHandler.MOVE );
              //     THIS is such a mess -- you can't do the following because
              //     getTransferable() throws an (undocumented) exception - what's that
              //     all about.
    //          Transferable t = dtde.getTransferable();
    //               if ( !t.isDataFlavourSupported( ROW_ARRAY_FLAVOR ) )
    //                    dtde.rejectDrop();
    //                    return false;
    //          TransferHandler handler = comp.getTransferHandler();
    //          if ( null == handler || ! handler.importData( comp, t ) )
    //               dtde.rejectDrop();
    //               return;
              Point p = dtde.getLocation();
              JTable table = ( JTable ) comp;
              rowIndex = table.rowAtPoint( p );
              //     So you have to do this instead and use the data that's been
              //     stored in the data member via import data.  Total mess.
              if ( null == data )
                   dtde.rejectDrop();
                   return;
              MyTableModel model = ( MyTableModel ) table.getModel();
              if ( rowIndex == -1 )
                   model.addRows( data );
              else
                   model.insertRows( rowIndex, data );
              dtde.acceptDrop( TransferHandler.MOVE );
         /** Called if the user has modified
          * the current drop gesture.
          * <P>
          * @param dtde the <code>DropTargetDragEvent</code>
         public void dropActionChanged(DropTargetDragEvent dtde)
    }

    Hi again,
    Well I've tried using the MouseListener / MouseMotionListener approach but it doesn't quite seem to work, although it does get the events correctly. I think the reason is that it doesn't interact correctly with the Java DnD machinery which is something that V.V hinted at. It's something that I may need to look into if / when I have more time available.
    I have to say though that I haven't had any problems with scrollbars - we're making fairly heavy use of large tables and if you drag over a table with a scroll bar and move to the top or bottom then it scrolls as you would expect and allows you to drop the data where you like. For this situation I've used pretty much the same approach as for the toy example above except that I've implemented separate source and destination TransferHandlers (the source table is read-only, and it really doesn't make sense to allow people to drag from the destination table so I've essentially split the functionality of the example handler down the middle).
    I'm not actually particularly in favour of messing too much with the mechanics of DnD, more because of lack of time than anything else. Guess I'll just have to put up with this for the moment. Doesn't help that DnD is so poorly documented by Sun.
    Thanks for all your help.
    Bart

Maybe you are looking for