Drag from JTable to JTree

Hello all,
is there a way to drag row(s) of a JTable to a node in a JTree?
I have a JTree that�s Drag and Drop enabled and wrks fine dragging one node to another (one by one...), but now I want to get data from a table to this tree. I have tried the method setDragEnabled(boolean) in the JTable object, but it didnt work...
thanks
D@zed

This is related to bug 5011850:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5011850
Crashes in the same place.

Similar Messages

  • 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

  • Reading values from JTable

    I have som problems reading the values from JTable. the user enters a number in the table, but some cells are empty. I want to store the values in an int array, and if the user has not filled a cell it is supposed to be set as zero. Now I cant seam to get it right.
    I get the error message: Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: null
    It is for the code. Integer intObj = new Integer(str);[/u
    int[] tmp = new int[brettStorelse * brettStorelse];
    for (int i = 0; i < brettStorelse; i++) {
         for (int j = 0; j < brettStorelse;j++) {
              String k = String.valueOf(j+i);
              int l = Integer.parseInt(k);
              if (sudokuTabell.getValueAt(i, j) != null) {
                   String str = (String) sudokuTabell.getValueAt(i+1, j+1);
                   Integer intObj = new Integer(str);
                   tmp[l] = intObj.intValue();
                   System.out.println(tmp[l]);
              } else {
                   tmp[l] = 0;

    What are you doing to prevent the user from entering values in the table that are not parseable? Seems like you should be doing the below.
    int[] tmp = new int[brettStorelse * brettStorelse];
    for (int i = 0; i < brettStorelse; i++) {
         for (int j = 0; j < brettStorelse;j++) {
              String k = String.valueOf(j+i);
              int l = Integer.parseInt(k);
              if (sudokuTabell.getValueAt(i, j) != null) {
                   String str = (String) sudokuTabell.getValueAt(i+1, j+1);
                            try {
                                tmp[l] = Integer.parseInt (str);
                            catch (NumberFormatException e){
                                 tmp[l] = 0;
                   System.out.println(tmp[l]);
              } else {
                   tmp[l] = 0;
    }

  • How can i do drag from cl_column_tree_mode drop to cl_gui_alv_grid ???

    Hi,
    I have building a program that will have one split screen and one of them has cl_column_tree_mode at top, and the other has cl_gui_alv_grid at bottom.
    I can Drag And Drop Lines From ALV GRID to TREE and i can use ONDRAG event of ALVGRID, DROP event of TREE Control and ONDROPCOMPLETE event of ALVGRID.
    But when i try to reverse it as like that Drag From TREE to ALVGRID, just DRAG event of TREE is triggering.
    I have implemented end registered ONDROP event for ALVGRID but it is no triggering.
    Have i something which missed ? Some of code at the above.
    *****************CODE****************************************
    *I created Application Ocject, Custom Container and Spliiter in here
    **       Definition of drag drop behaviour
        create object behaviour_top.
        call method behaviour_top->add
            exporting
                  flavor = 'LINEFROM' "I dont know where i can use this
                  dragsrc = 'X'
                  droptarget = 'X'
                  effect = cl_dragdrop=>move.
        call method behaviour_top->add
             exporting
                   flavor = 'LINETO'   "I dont know where i can use this
                   dragsrc = 'X'
                   droptarget = 'X'
                   effect = cl_dragdrop=>move.
        call method behaviour_top->get_handle
             importing handle = handle_top. "I am not sure that i can use this handle for both TREE Nodes and ALV Rows, But i am using it for both.
    ******************************   TREE   ********************************
    *   CREATE TREE
        ls_treemhhdr-heading = 'Nakliye ve Makaralar'.
        ls_treemhhdr-width   =  35.
        create object gref_column_tree
         exporting
         node_selection_mode   = cl_column_tree_model=>node_sel_mode_single
         item_selection        = space
         hierarchy_column_name = 'NUMBER'
         hierarchy_header      = ls_treemhhdr.
        call method gref_column_tree->create_tree_control
          exporting
            parent                       = container_1    .
    *   Events for tree control
        set handler g_application->handle_tree_drag for gref_column_tree.
        set handler g_application->handle_tree_drop for gref_column_tree.
    *   Build TREE
        perform build_tree using gref_column_tree. "I use HANDLE_TOP in this when creating nodes.
    ******************************   TREE   ********************************
    ****************************  ALV GRID  ********************************
    *   create ALV Grid
        create object alv_grid
                      exporting i_parent = container_2.
    *   Events alv control
        set handler g_application->handle_alv_drag for alv_grid.
        set handler g_application->handle_alv_drop for alv_grid.
        set handler g_application->handle_alv_drop_complete for alv_grid.
        gs_layout-grid_title = '&#304;s Listesi'.
        gs_layout-s_dragdrop-row_ddid = handle_top. "I think this is a important thing
        call method alv_grid->set_table_for_first_display
             exporting is_layout        = gs_layout
             changing  it_fieldcatalog  = gt_fieldcat
                       it_outtab        = i_tabout[].
    ****************************  ALV GRID  ********************************
    *I have implemented all methods for this class, it hink its not important to see *which code its has, important is why its not triggering.
    class lcl_application definition.
      public section.
        data: next_node_key type i.
        methods:
    *   ALV EVENTS
        handle_alv_drag for event ondrag of cl_gui_alv_grid
            importing e_row e_column e_dragdropobj,
        handle_alv_drop for event  ondrop of cl_gui_alv_grid
            importing e_row e_column es_row_no e_dragdropobj,
        handle_alv_drop_complete for event ondropcomplete of cl_gui_alv_grid
            importing e_row e_column e_dragdropobj,
    *   TREE EVENTS
        handle_tree_drag for event drag  of cl_column_tree_model
            importing node_key item_name drag_drop_object,
        handle_tree_drop for event drop  of cl_column_tree_model
            importing node_key drag_drop_object,
        handle_tree_drop_complete for event drop_complete of cl_column_tree_model
            importing node_key ITEM_NAME drag_drop_object.
    endclass.

    Thanks kaipha,
    in examples in SE83 i have noticed that i have to create an inctance for drag drop object when drag starts.
      method handle_tree_drag.
        data: "local_node_table type node_table_type,
              new_node type mtreesnode,
              dataobj type ref to lcl_dragdropobj_from_tree,
              l_keytxt(30) type c.
        catch system-exceptions move_cast_error = 1.
    *           create and fill dataobject for events ONDROP and ONDROPCOMPLETE
                create object dataobj. "When i create dataobj in here
                move node_key to dataobj->node_key.
                drag_drop_object->object = dataobj. "And when i call this method, ALV Drop event has begin triggered
        endcatch.
        if sy-subrc <> 0.
          call method drag_drop_object->abort.
        endif.
      endmethod.

  • Drag From cl_column_tree_model To cl_gui_alv_grid Is not Working ???

    Hi,
    I have building a program that will have one split screen and one of them has cl_column_tree_mode at top, and the other has cl_gui_alv_grid at bottom.
    I can Drag And Drop Lines From ALV GRID to TREE and i can use ONDRAG event of ALVGRID, DROP event of TREE Control and ONDROPCOMPLETE event of ALVGRID.
    But when i try to reverse it as like that Drag From TREE to ALVGRID, just DRAG event of TREE is triggering.
    I have implemented end registered ONDROP event for ALVGRID but it is no triggering.
    Have i something which missed ? Some of code at the above.
    *****************CODE****************************************
    *I created Application Ocject, Custom Container and Spliiter in here
    **       Definition of drag drop behaviour
        create object behaviour_top.
        call method behaviour_top->add
            exporting
                  flavor = 'LINEFROM' "I dont know where i can use this
                  dragsrc = 'X'
                  droptarget = 'X'
                  effect = cl_dragdrop=>move.
        call method behaviour_top->add
             exporting
                   flavor = 'LINETO'   "I dont know where i can use this
                   dragsrc = 'X'
                   droptarget = 'X'
                   effect = cl_dragdrop=>move.
        call method behaviour_top->get_handle
             importing handle = handle_top. "I am not sure that i can use this handle for both TREE Nodes and ALV Rows, But i am using it for both.
    ******************************   TREE   ********************************
    *   CREATE TREE
        ls_treemhhdr-heading = 'Nakliye ve Makaralar'.
        ls_treemhhdr-width   =  35.
        create object gref_column_tree
         exporting
         node_selection_mode   = cl_column_tree_model=>node_sel_mode_single
         item_selection        = space
         hierarchy_column_name = 'NUMBER'
         hierarchy_header      = ls_treemhhdr.
        call method gref_column_tree->create_tree_control
          exporting
            parent                       = container_1    .
    *   Events for tree control
        set handler g_application->handle_tree_drag for gref_column_tree.
        set handler g_application->handle_tree_drop for gref_column_tree.
    *   Build TREE
        perform build_tree using gref_column_tree. "I use HANDLE_TOP in this when creating nodes.
    ******************************   TREE   ********************************
    ****************************  ALV GRID  ********************************
    *   create ALV Grid
        create object alv_grid
                      exporting i_parent = container_2.
    *   Events alv control
        set handler g_application->handle_alv_drag for alv_grid.
        set handler g_application->handle_alv_drop for alv_grid.
        set handler g_application->handle_alv_drop_complete for alv_grid.
        gs_layout-grid_title = '&#304;s Listesi'.
        gs_layout-s_dragdrop-row_ddid = handle_top. "I think this is a important thing
        call method alv_grid->set_table_for_first_display
             exporting is_layout        = gs_layout
             changing  it_fieldcatalog  = gt_fieldcat
                       it_outtab        = i_tabout[].
    ****************************  ALV GRID  ********************************
    *I have implemented all methods for this class, it hink its not important to see *which code its has, important is why its not triggering.
    class lcl_application definition.
      public section.
        data: next_node_key type i.
        methods:
    *   ALV EVENTS
        handle_alv_drag for event ondrag of cl_gui_alv_grid
            importing e_row e_column e_dragdropobj,
        handle_alv_drop for event  ondrop of cl_gui_alv_grid
            importing e_row e_column es_row_no e_dragdropobj,
        handle_alv_drop_complete for event ondropcomplete of cl_gui_alv_grid
            importing e_row e_column e_dragdropobj,
    *   TREE EVENTS
        handle_tree_drag for event drag  of cl_column_tree_model
            importing node_key item_name drag_drop_object,
        handle_tree_drop for event drop  of cl_column_tree_model
            importing node_key drag_drop_object,
        handle_tree_drop_complete for event drop_complete of cl_column_tree_model
            importing node_key ITEM_NAME drag_drop_object.
    endclass.

    Thanks kaipha,
    in examples in SE83 i have noticed that i have to create an inctance for drag drop object when drag starts.
      method handle_tree_drag.
        data: "local_node_table type node_table_type,
              new_node type mtreesnode,
              dataobj type ref to lcl_dragdropobj_from_tree,
              l_keytxt(30) type c.
        catch system-exceptions move_cast_error = 1.
    *           create and fill dataobject for events ONDROP and ONDROPCOMPLETE
                create object dataobj. "When i create dataobj in here
                move node_key to dataobj->node_key.
                drag_drop_object->object = dataobj. "And when i call this method, ALV Drop event has begin triggered
        endcatch.
        if sy-subrc <> 0.
          call method drag_drop_object->abort.
        endif.
      endmethod.

  • ITunes will not allow me to drag files onto my desktop or a USB drive. The files still come up in finder and I can drag from there but I need entire playlists transferred. It started this when Yosemite went public and I updated out of BETA.

    Songs and Playlists cannot be dragged from the itunes app onto desktop or usb drives.
    Files can be dragged from Finder but only one at a time.
    The issue started when I updated Yosemite out of BETA.
    I am running:
    OS X Yosemite 10.10
    2013 Macbook Pro
    iTunes 12.0.1

    Hey! I had the same problem you did just today when I was trying to get my second iPhone to sync. What you need to do with music or anything extra that you doing you have to creat a second playlist or picture or anything that you would like to use, so that you can add to the second device that you are going to be using. I am not sure if that will help but it helped me out a lot!! Good luck!

  • Lacking true native "Deferred" or "Promised" file drag from JAVA

    Hello all,
    I have been playing around with the drag and drop APIs for quite some time (about 1.5+ years) and I am having a problem producing functionality similar to dragging network-based files in "Windows Explorer". I am not sure if I have overlooked something or if DnD with the native OS is lacking a huge piece of functionality. I would appreciate hearing people's feedback or experience with similar problems.
    First, some background. My company's applications provide remote access to a central storage of digital assets (read "files"). Our client provides a view of the files on the server. We have C++-based applications running on both Windows and the Macintosh are able to drag from our application to the desktops and Explorer windows. However, in these drag operations, they each employ a mechanism to hold-off providing the native OS file data until the drop has successfully completed. The OS in each case provides a "callback" to notify our application that the drop succeeded and that we should go and transfer the files. In this way, we can pay the price of transferring the files locally ONLY when the drop occurs (same thing can be applied to the Clipboard).
    However, from what I can tell, the AWT/SWING DnD APIs provide no mechanism to do this type of operation. In order to drag files to the native OS, you must explicitly provide the files BEFORE you initiate the drag operation (or place them on the clipboard). This places doing viable native drag and drop from our JAVA applications in serious jeopardy and is causing a great deal of displeasure from our management who are questioning the "readiness" of JAVA.
    Since I can't seem to find a way to accomplish this, I have tried entering enhancement requests (about 8 to date), but I have failed to hear back about a single one. I think that either Sun does not monitor some of their enhancement lists or they do not want to address this heavily-desktop oriented issue (I am not sure if this scenario is even possible on a UNIX machine where most things must be "mounted" locally before they can be viewed -- SMB browsing may be the only exception that comes to mind but I do not know if anyone has done this).
    In the meantime, we have attempted to change the workflow of our application. We have provided a JAVA window that mimics the filesystem so that we can get the drop event and provide the illusion of a "deferred" drag. In addition, we have provided and "export" feature that places the file locally afterwhich they may grad anywhere they desire. Both of these solutions are hacks and leave a very bad taste in our user's mouths. We can try to write JNI pieces, however, there are just too many UI locking issues to contend with to ensure a timely release of our software.
    Has anyone else run into this before? Can anyone provide a more useful workaround? Is it possible to get this issue looked at from SUN? If SUN is looking at it already, what kind of timeframe are we looking at until a potential solution?
    Thank you for your time.
    Michael Macaluso

    I am curious about the verdict for "deferred" file transfers. I have hit the same wall. I have a JAVA client window that allows the user to browse a network file repository. Most of our clients use a Windows platform, so that is my primary interest. I was hoping to: 1)capture the drop event, 2) request the data from the server, and 3) stream it to a temp file/ or to the destination directory, and 4)allow the file system to transfer the temp file. However, I cannot find any documentation regarding this issue.
    So I wanted to swtich tracks and set my transferrable data to represent a file on the central server, but that would require a URL object, and I have failed to set the MIME types correctly for NTFS to recongize the transfer. Sorry I don't have any answers. Any suggestions?

  • Add and remove columns from JTable

    Help me please!
    A try to remove column from JTable. It's removed, but when I try to add column in table, then I get all old (removed early) columns + new column....
    I completely confused with it.....
    Here is my code for remove column:
    class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             table.getColumnModel().removeColumn (tableCModel.getColumn (HowManyColDelete [ i ]));
                   else
                          JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         }

    It's little ex for me, I just try understand clearly how it's work (table models i mean). Here is code. All action with tables take place through menu items.
    My brain is boiled, I've try a lot of variants of code, but did't get right result :((
    It's code represent problem, which I've describe above. If you'll try remove column and then add it again, it will be ma-a-a-any colunms...
    I understand, that my code just hide columns, not delete from table model....
    But now I have not any decision of my problem...
    Thanks a lot for any help. :)
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import javax.swing.table.DefaultTableModel;
    class JTableF extends JFrame
         Object [] [] data = new Object [0] [2];
         JTable table;
         DefaultTableModel model;
         String [] columnNames = {"1", "2"};
         TableColumnModel cm;
         JTableF()
              super("Table features");
              setDefaultLookAndFeelDecorated( true );
              setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              JMenuBar MBar = new JMenuBar();
              JMenu [] menus =  {new JMenu("A"), new JMenu("B")};
              JMenuItem [] menu1 =  {new JMenuItem("Add row"), new JMenuItem("Delete row", 'D'),  new JMenuItem("Add column"), new JMenuItem("Delete column")};
              menu1 [ 0 ].addActionListener(new AddL());
              menu1 [ 1 ].addActionListener(new DelL());
              menu1 [ 2 ].addActionListener(new AddC());
              menu1 [ 3 ].addActionListener(new DelC());
              for (int i=0; i<menu1.length; i++)
                   menus [ 0 ].add( menu1 [ i ]);
              for (int i=0; i<menus.length; i++)
                   MBar.add(menus );
              JPanel panel = new JPanel ();
              model = new DefaultTableModel( data, columnNames );
              table = new JTable (model);
              cm = table.getColumnModel();
              panel.add (new JScrollPane(table));
              JButton b = new JButton ("Add row button");
              b.addActionListener(new AddL());
              panel.add (b);
              setJMenuBar (MBar);
              getContentPane().add(panel);
              pack();
              setLocationRelativeTo (null);
              setVisible (true);
         class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             int vizibleCol = table.convertColumnIndexToView(HowManyColDelete [ i ]);
                             tableCModel.removeColumn (tableCModel.getColumn (vizibleCol));
                        //cm = tableCModel;
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         class AddC implements ActionListener
              public void actionPerformed (ActionEvent e)
                   //table.setColumnModel(cm);
                   Object NewColumnName = new String();
                   NewColumnName = JOptionPane.showInputDialog ("Input new column name", "Here");
                   int i = model.getRowCount();
                   int j = model.getColumnCount();
                   Object [] newData = new Object [ i ];
                   model.addColumn ( NewColumnName, newData);
         class AddL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int i = model.getColumnCount();
                   Object [] Row = new Object [ i ];
                   model.addRow ( Row );
         class DelL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int [] HowManyRowsDelete = table.getSelectedRows();
                   if (HowManyRowsDelete.length !=0)
                        for (int k = HowManyRowsDelete.length-1; k>-1; k--)
                             model.removeRow (HowManyRowsDelete[k]);
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Row is not selected!");
         public static void main (String [] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        JTableF inst = new JTableF();

  • How to remove a row from JTable

    Hi!
    I'm used to remove rows from JTables getting the model and doing a removeRow(num) like this:
    ((DefaultTableModel)jTable1.getModel()).removeRow(0);
    But with ADF and JDeveloper the model says it's a JUTableBinding.JUTableModel but its not accessible.
    How to remove a row in Jdeveloper 10.1.3.4.0?

    Or maybe is just better to refresh data in the jTable but I do not know either like doing it.

  • Can't Drag from iTunes into Garageband anymore

    After routine software update to iTunes 10 and Garageband 09 version 5.1,  I can no longer drag files from iTunes into Garageband, whereas I always could before. Whats wrong?  I'm using an iMac with a 3.06 GHz Intel Core 2 Duo Processor with 4 GB 1067 MHz DDR3 memory.

    Somehow, when I tried to drag from the finder, I didn't always get the right song!  But if I double clicked that song in the finder, the right song was played by iTunes, even though the wrong song showed up in Garage Band.  Dragging to and from the desktop worked fine, and I just dragged it from the desktop to the trash after I worked on it in Garage Band for editing and "sharing" back into iTunes.

  • How to get the default selection color from JTable

    Hi, there,
    I have a question for how to get the default selection color from JTable. I am currently implementing the customized table cell renderer, but I do want to set the selection color in the table exactly the same of default table cell renderer. The JTable.getSelectionBackgroup() did not works for me, it returned dark blue which made the text in the table unreadable. Anyone know how to get the window's default selection color?
    Thanks,
    -Jenny

    The windows default selection color is dark blue. Try selecting any text on this page. The difference is that the text gets changed to a white font so you can actually see the text.
    If you don't like the default colors that Java uses then use the UIManager to change the defaults. The following program shows all the properties controlled by the UIManager:
    http://www.discoverteenergy.com/files/ShowUIDefaults.java
    Any of the properties can be changed for the entire application by using:
    UIManager.put( "propertyName", value );

  • Can someone pls tell me why is it that i cant drag from the itunes movies to the playlist, but i can drag the songs to the playlist.  Thanks.

    Hi, can someone pls tell me why is it that I can't drag from the itunes movie library to the playlist, but able to drag songs to the playlist.  Thnaks.

    Are you able to receive any mail at all? If not, make sure that all of your information for mail is accurate in settings again. if you still have nothing, go to your email through safari. (example: www.yahoo.com) If you do not see the emails here either, it is a problem with the password reset server not your mail app.

  • Drag from one Browser pane to another?

    Hi. Ap3 (and earlier? -- I don't know) has a potentially useful feature of being able to open multiple panes in the Browser, each pane showing different content. (Page 124 in the Manual. Option+Click an item in the Library tab of the Inspector.) A natural use of this -- to me -- is to open two projects and move images between them. That is apparently not how it works, or else I am doing something wrong. Any help?
    Thanks.

    DLScreative wrote:
    Me too. It's a small annoyance but an annoyance nonetheless.
    At least the Project names of the Projects with open Browsers are shown with some kind of highlighting. I can find them easily enough, though I'd rather
    . not have the Inspector open, and
    . just be able to drag from Browser to Browser.
    Thanks for commenting. Glad to know others share my (minor) frustration.

  • [svn:fx-trunk] 10943: Fix to dragging from List with multiple-selection

    Revision: 10943
    Author:   [email protected]
    Date:     2009-10-08 15:46:27 -0700 (Thu, 08 Oct 2009)
    Log Message:
    Fix to dragging from List with multiple-selection
    - The fix is to postpone the selection commit until we make sure the user has not started a drag gesture.
    - Exclude the dragEnabled, dropEnabled, dragMoveEnabled properties for DropDownList
    QE notes: None
    Doc notes: None
    Bugs: None
    Reviewer: Deepa
    Tests run: checkintests, mustella List, DropDownList
    Is noteworthy for integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/DropDownList.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/List.as

  • Drag from Lightroom 3 to Photodex Producer

    I use to be able drag from Media Expressions/Ivew Media Pro to Photodex Producer when building slideshows, it worked fine.
    I tried using Lightroom 3 from library module to producer and it did not work.
    Is there a way to do this in Lightroom3?
    I wanted to use the dam part of lightroom instead of Media Expressions which I don't think Microsoft is going to keep updated.

    Thanks for the info.
    I found a Lightroom Plugin from Photodex that does it and more.
    I will not be using media expressions as that was one reason I upgraded to Lightroom 3, to catalog and play video as well.
    I will do everything in lightroom 3 thankfully at last !!!!!!!

Maybe you are looking for

  • Flash Player not working in IE8 or IE9

    Had been using IE9 and all of a sudden had problems on all sites with Flash.  Went to a website and was prompted to "Click to install activex control: Adobe Flash Player". When I click to install, I get the error message that the "Flash Player I am t

  • Playing video clips within Photos app

    I have a pile of video clips taken with a compact Sony player that outputs in MPEG1. Using MPEG Streamclip I converted a number of them into MPEG4 so I could view them on my iPad along with the photos taken at the same time. The problem I have is tha

  • CATSDB values are copied from HR in real-time

    We use default values in IT 315 to report in CATS.  At some point we have discovered wrong default values and changed them in the HR records. But the "wrong" values were already copied into CATSDB table for posting, even though entries are not posted

  • Exporting iPhoto comments

    I'm (still) using iPhoto 6 and wish to export my detailed comments with my photos. I tried Old Toads suggestion, but it would not work for me: http://discussions.apple.com/thread.jspa?messageID=4276855&#4276855 I would update to iPhoto 7 tomorrow if

  • Requirement of DSC Runtime License

    Hi I am having an application developed using DSC8.5.1 which is designed as a server to collect data from Modbus devices and configured for datalogging,alarming,trending.I have purchased one DSC runtime license for running the executable.Now I need t