Multiple columns Drag n Drop in JTable

Issue:
I'm building a JTable with groupable column headers like this:
GROUP A_ | GROUP B_
col1 | col2 | col3 | col4
I based this on the GroupableHeader example at: http://www2.gol.com/users/tame/swing/examples/JTableExamples1.html
Question:
How would I approach allowing the user to reorder Groups by dragging
the Group level header(GROUP A_) and all of its subordinate columns (col1 and col2) and dropping into a new location. I'd like to simulate the standard JTable column DnD animation - but with groups of columns.

Have you solved this problem ? I have the same question.

Similar Messages

  • How Can I Put Multiple Columns in a Drop-Down Menu?

    We are trying to put multiple columns in a drop-down menu, similar to what is on these web sites...
    http://www.cabelas.com/
    http://www.target.com/  (This site has the multiple columns on the Women, Home, Kitching & Dining, Toys, Electronics, and See More categories).
    If anyone has any suggestions for coding, please reply.
    Thank you.
    Wil Radcliffe

    As an <li> tag is not a block level element like a <p> or <div> tag you can store a <div> container within the <li> tag and create an element in that menu item and us the following tutorial to create multiple columns depending on the ordering:
    http://www.alistapart.com/articles/multicolumnlists
    Depending on your target browser you could also use the CSS3 column-count to define the amount of columns.  But with just a quick glance at this I would say it only works in the the later versions of Firefox, Chrome, Safari and IE9+.
    http://www.w3schools.com/cssref/css3_pr_column-count.asp

  • MULTIPLE-ROW drag and drop between 2 ALV grids

    Hi,
    Can anybody help me with acheiving MULTIPLE-ROW drag and drop functionality between 2 ALV grids.

    hi Prakash,
    Actually I'm trying to develop multiple drag and drop between 2 ALV's. To understand the events properly, I started working on this sample program where it uses 1 ALV and splits it into 2 and uses single row drag and drop between them. Now I'm making it to work for multiple drag and drop, so that I can use it on my application. This is the code which I'm working on..
    *& Report  Z_ALV_GRID_CONTROLS_DRAG_DROP                               *
    REPORT  z_alv_grid_controls_drag_drop.
    DATA   : i_ztransactions  TYPE TABLE OF ztransactions
                                   WITH HEADER LINE.
    DATA   : i_ztransactions2 TYPE TABLE OF ztransactions
                                   WITH HEADER LINE.
    DATA   : ok_code LIKE sy-ucomm .
    DATA : mcontainer TYPE REF TO cl_gui_custom_container .
    DATA : mcontleft  TYPE REF TO cl_gui_container .
    DATA : mcontright TYPE REF TO cl_gui_container .
    DATA : msplitcont TYPE REF TO
                            cl_gui_easy_splitter_container .
    DATA : malv_left  TYPE REF TO cl_gui_alv_grid .
    DATA : malv_right TYPE REF TO cl_gui_alv_grid .
    DATA : mrow TYPE lvc_s_row .
    DATA : gt_outtab_source TYPE ztransactions.
    DATA : gt_outtab_target TYPE ztransactions.
    DATA : g_repid LIKE sy-repid.
    DATA:   gs_layout TYPE lvc_s_layo ,
            g_behaviour_alv TYPE REF TO cl_dragdrop .
    DATA : mlines TYPE i .
          CLASS lcl_dragdropobj DEFINITION
    This is the Class of Drag Drop Object .
    This Object is used as a temporary storage means
    of the information extracted with drag
    CLASS lcl_dragdropobj DEFINITION.
      PUBLIC SECTION.
        DATA: i_ztransactions  TYPE ztransactions ,
              index TYPE i ,
              original_table(5) TYPE c ,
              proceed_trans(1) TYPE c .
    ENDCLASS.                    "lcl_dragdropobj DEFINITION
    DATA : mdata TYPE REF TO lcl_dragdropobj .
          CLASS DND_TOOLS DEFINITION
    This class contains the methods responding to the
    events ONDRAG , ONDROP , ONDROPCOMPLETE
    of the ALV Grid Controls
    CLASS dnd_tools DEFINITION .
      PUBLIC SECTION .
       METHODS:handle_user_command
                               FOR EVENT user_command OF
                               cl_gui_alv_grid
                               IMPORTING
                               e_ucomm.
        METHODS : handle_drag_from_left
                             FOR EVENT ondrag OF
                              cl_gui_alv_grid
                              IMPORTING
                              e_row
                              e_dragdropobj .
        METHODS : handle_dropcomplete_from_left
                              FOR EVENT ondropcomplete  OF
                              cl_gui_alv_grid
                              IMPORTING
                              e_row
                              e_dragdropobj .
        METHODS : handle_drag_from_right
                              FOR EVENT ondrag OF
                              cl_gui_alv_grid
                              IMPORTING
                              e_row
                              e_dragdropobj .
        METHODS : handle_dropcomplete_from_right
                              FOR EVENT ondropcomplete  OF
                              cl_gui_alv_grid
                              IMPORTING
                              e_row
                              e_dragdropobj .
        METHODS : handle_drop_to_left
                              FOR EVENT ondrop OF
                              cl_gui_alv_grid
                              IMPORTING
                               e_dragdropobj .
        METHODS : handle_drop_to_right
                              FOR EVENT ondrop OF
                              cl_gui_alv_grid
                              IMPORTING
                              e_dragdropobj .
    ENDCLASS .                    "DND_TOOLS DEFINITION
          CLASS DND_TOOLS IMPLEMENTATION
    CLASS dnd_tools IMPLEMENTATION .
      METHOD handle_drag_from_left .
    METHOD handle_user_command.
       DATA: lt_rows TYPE lvc_t_row.
        DATA: lt_rows TYPE lvc_t_roid.
        DATA: lt_row TYPE lvc_s_roid.
        DATA: mdata TYPE REF TO lcl_dragdropobj .
        DATA: dragdropobj TYPE REF TO lcl_dragdropobj .
    get selected row
        CALL METHOD malv_left->get_selected_rows
          IMPORTING
            et_row_no = lt_rows.
        CALL METHOD cl_gui_cfw=>flush.
        IF sy-subrc NE 0.
    add your handling, for example
          CALL FUNCTION 'POPUP_TO_INFORM'
            EXPORTING
              titel = g_repid
              txt2  = sy-subrc
              txt1  = 'Error in Flush'(500).
        ENDIF.
        CREATE OBJECT mdata.
        LOOP AT lt_rows INTO lt_row.
         mrow = lt_row .
          READ TABLE i_ztransactions INDEX lt_row-row_id INTO
                     i_ztransactions.
          MOVE i_ztransactions TO mdata->i_ztransactions .
          MOVE lt_row-row_id TO mdata->index.
          MOVE 'LEFT' TO mdata->original_table .
          e_dragdropobj->object = mdata .
        ENDLOOP.
      ENDMETHOD.                           "handle_user_command
      METHOD handle_dropcomplete_from_left .
      NB : the following data object MDATA is local to
      the method and contains the information from the
      import parameter of the method E_DRAGDROPOBJ
        DATA : mdata TYPE REF TO lcl_dragdropobj .
        DATA: lt_rows TYPE lvc_t_roid.
        DATA: lt_row TYPE lvc_s_roid.
        CALL METHOD malv_left->get_selected_rows
          IMPORTING
            et_row_no = lt_rows.
        CALL METHOD cl_gui_cfw=>flush.
        IF sy-subrc NE 0.
    add your handling, for example
          CALL FUNCTION 'POPUP_TO_INFORM'
            EXPORTING
              titel = g_repid
              txt2  = sy-subrc
              txt1  = 'Error in Flush'(500).
        ENDIF.
        LOOP AT lt_rows INTO lt_row.
          mdata  ?= e_dragdropobj->object .
          CHECK mdata->proceed_trans = 'X' .
          mrow = mdata->index.
          DELETE i_ztransactions INDEX mrow .
          APPEND mdata->i_ztransactions TO i_ztransactions2 .
          SORT i_ztransactions2 BY kunnr belnr .
          DELETE i_ztransactions2 WHERE kunnr IS INITIAL .
          DESCRIBE TABLE i_ztransactions LINES mlines .
          IF mlines EQ 0 .
            CLEAR  i_ztransactions .
            APPEND i_ztransactions TO i_ztransactions .
          ENDIF .
        ENDLOOP.
        CALL METHOD malv_left->refresh_table_display.
        CALL METHOD malv_right->refresh_table_display.
      ENDMETHOD .                    "HANDLE_DROPCOMPLETE_FROM_LEFT
      METHOD handle_drag_from_right.
        mrow = e_row-index .
        READ TABLE i_ztransactions2 INDEX mrow INTO
                   i_ztransactions2 .
        CREATE OBJECT mdata .
        MOVE i_ztransactions2 TO mdata->i_ztransactions .
        MOVE mrow TO mdata->index .
        MOVE 'RIGHT' TO mdata->original_table .
        e_dragdropobj->object = mdata .
      ENDMETHOD .                    "HANDLE_DRAG_FROM_RIGHT
      METHOD handle_dropcomplete_from_right .
        DATA : mdata TYPE REF TO lcl_dragdropobj .
        mdata  ?= e_dragdropobj->object .
        CHECK mdata->proceed_trans = 'X' .
        mrow = mdata->index .
        DELETE i_ztransactions2 INDEX mrow .
        APPEND mdata->i_ztransactions TO i_ztransactions .
        SORT i_ztransactions BY kunnr belnr .
        DELETE i_ztransactions WHERE kunnr IS INITIAL .
        DESCRIBE TABLE i_ztransactions2 LINES mlines .
        IF mlines EQ 0 .
          CLEAR  i_ztransactions2 .
          APPEND i_ztransactions2 TO i_ztransactions2 .
        ENDIF .
        CALL METHOD malv_left->refresh_table_display.
        CALL METHOD malv_right->refresh_table_display.
      ENDMETHOD .                    "HANDLE_DROPCOMPLETE_FROM_RIGHT
      METHOD handle_drop_to_left .
        DATA : mdata TYPE REF TO lcl_dragdropobj .
        mdata  ?= e_dragdropobj->object .
        IF mdata->original_table = 'RIGHT' .
          mdata->proceed_trans = 'X' .
        ELSE .
          mdata->proceed_trans = ' ' .
        ENDIF .
        e_dragdropobj->object = mdata .
      ENDMETHOD .                    "HANDLE_DROP_TO_LEFT
      METHOD handle_drop_to_right .
        DATA : mdata TYPE REF TO lcl_dragdropobj .
        DATA: lt_rows TYPE lvc_t_roid.
        DATA: lt_row TYPE lvc_s_roid.
        CALL METHOD malv_left->get_selected_rows
          IMPORTING
            et_row_no = lt_rows.
        CALL METHOD cl_gui_cfw=>flush.
        IF sy-subrc NE 0.
    add your handling, for example
          CALL FUNCTION 'POPUP_TO_INFORM'
            EXPORTING
              titel = g_repid
              txt2  = sy-subrc
              txt1  = 'Error in Flush'(500).
        ENDIF.
        LOOP AT lt_rows INTO lt_row.
          mdata  ?= e_dragdropobj->object .
          IF mdata->original_table = 'LEFT' .
            mdata->proceed_trans = 'X' .
          ELSE .
            mdata->proceed_trans = ' ' .
          ENDIF .
          e_dragdropobj->object = mdata .
        ENDLOOP.
      ENDMETHOD .                    "HANDLE_DROP_TO_RIGHT
    ENDCLASS .                    "DND_TOOLS IMPLEMENTATION
    DATA : mlistener TYPE REF TO dnd_tools .
    ======================================================
    START OF SELECTION
    ======================================================
    START-OF-SELECTION .
      PERFORM get_data .
      CALL SCREEN 100 .
    The screen 100 has the custom control MCONTAINER and
    on the flow logic has the following modules :
    PROCESS BEFORE OUTPUT.
      MODULE STATUS_0100.
      MODULE PREPARE_SCREEN .
    PROCESS AFTER INPUT.
      MODULE USER_COMMAND_0100.
    (Off course not commented out in the real flow logic)
          FORM GET_DATA                                 *
    FOR THIS EXAMPLE THE DATA SELECTION IS HARD CODED
    FORM get_data .
      CLEAR : i_ztransactions , i_ztransactions[] .
      i_ztransactions-mandt = sy-mandt .
      i_ztransactions-waers = 'EUR  ' .
      i_ztransactions-kunnr = '0000000001' .
      i_ztransactions-belnr = '0000000001' .
      i_ztransactions-bldat = '20030101' .
    i_ztransactions-dmbtr = '1000' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000002' .
      i_ztransactions-bldat = '20030202' .
    i_ztransactions-dmbtr = '1010' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000003' .
      i_ztransactions-bldat = '20030323' .
    i_ztransactions-dmbtr = '1020' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000004' .
      i_ztransactions-bldat = '20030404' .
    i_ztransactions-dmbtr = '1030' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000005' .
      i_ztransactions-bldat = '20030505' .
    i_ztransactions-dmbtr = '1040' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000006' .
      i_ztransactions-bldat = '20030606' .
    i_ztransactions-dmbtr = '1050' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000007' .
      i_ztransactions-bldat = '20030707' .
    i_ztransactions-dmbtr = '1060' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000008' .
      i_ztransactions-bldat = '20030808' .
    i_ztransactions-dmbtr = '1070' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000009' .
      i_ztransactions-bldat = '20030909' .
    i_ztransactions-dmbtr = '1080' .
      APPEND i_ztransactions .
      i_ztransactions-belnr = '0000000010' .
      i_ztransactions-bldat = '20031010' .
    i_ztransactions-dmbtr = '1090' .
      APPEND i_ztransactions .
      CLEAR : i_ztransactions2 , i_ztransactions2[] .
      APPEND i_ztransactions2 .
    ENDFORM .                    "GET_DATA
    *&      Module  STATUS_0100  OUTPUT
    The PF STATUS STATUS100 called from the module below,
    has on the Standard toolbar the buttons
    BACK , EXIT and CANCEL .
    These buttons are provided with function code = 'EXIT'
    MODULE status_0100 OUTPUT.
      SET TITLEBAR 'TITLEDRAGDROP' .
      SET PF-STATUS 'STATUS100'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
         Module  USER_COMMAND_0100  INPUT
    The following module checks the User Command and ends
    the program
    MODULE user_command_0100 INPUT.
      IF ok_code = 'EXIT' .
        CLEAR : mcontainer ,
               mcontleft  ,
               mcontright ,
               msplitcont ,
               malv_left  ,
               malv_right .
        LEAVE TO SCREEN 0  .
      ENDIF .
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Module  PREPARE_SCREEN  OUTPUT
    MODULE prepare_screen OUTPUT.
      IF mcontainer IS INITIAL .
        CREATE OBJECT mcontainer
                      EXPORTING
                      container_name = 'MCONTAINER' .
        CREATE OBJECT msplitcont
                      EXPORTING
                      parent = mcontainer
                      orientation = 1 .
        mcontleft = msplitcont->top_left_container .
        mcontright = msplitcont->bottom_right_container .
        CREATE OBJECT malv_left
                      EXPORTING i_parent = mcontleft .
        gs_layout-sel_mode = 'D'.
        CREATE OBJECT malv_right
                      EXPORTING i_parent = mcontright .
        gs_layout-sel_mode = 'D'.
        PERFORM set_layout_capable_of_drag_dro
                      USING 'X' 'X' .
        CALL METHOD malv_left->set_table_for_first_display
          EXPORTING
            i_structure_name = 'ZTRANSACTIONS'
            is_layout        = gs_layout
          CHANGING
            it_outtab        = i_ztransactions[].
        CALL METHOD malv_right->set_table_for_first_display
          EXPORTING
            i_structure_name = 'ZTRANSACTIONS'
            is_layout        = gs_layout
          CHANGING
            it_outtab        = i_ztransactions2[].
        CREATE OBJECT mlistener .
        CALL METHOD malv_left->set_toolbar_interactive.
        SET HANDLER mlistener->handle_drag_from_left
                    FOR malv_left .
        SET HANDLER mlistener->handle_dropcomplete_from_left
                    FOR malv_left .
        SET HANDLER mlistener->handle_drag_from_right
                    FOR malv_right.
        SET HANDLER mlistener->handle_dropcomplete_from_right
                      FOR malv_right .
        SET HANDLER mlistener->handle_drop_to_right
                     FOR malv_right .
        SET HANDLER mlistener->handle_drop_to_left
                     FOR malv_left  .
      ENDIF .
    ENDMODULE.                 " PREPARE_SCREEN  OUTPUT
          Form  SET_LAYOUT_CAPABLE_OF_DRAG_DRO
    Definition of a Drag & Drop behaviour for the ALV
    grid
    FORM set_layout_capable_of_drag_dro  USING drag drop.
      DATA : effect TYPE i ,
             handle_alv TYPE i .
      CREATE OBJECT g_behaviour_alv.
      effect = cl_dragdrop=>move + cl_dragdrop=>copy .
      CALL METHOD g_behaviour_alv->add
        EXPORTING
          flavor     = 'Line'
          dragsrc    = drag
          droptarget = drop
          effect     = effect.
      CALL METHOD g_behaviour_alv->get_handle
        IMPORTING
          handle = handle_alv.
      gs_layout-s_dragdrop-row_ddid = handle_alv.
    ENDFORM.              " SET_LAYOUT_CAPABLE_OF_DRAG_DRO

  • Is it possibiel to disable drag and drop of JTable columns?

    Hi,
    Using JDK6 I would like to disable user to drag and drop columns and change the default layout of my JTables.
    Thanks for any help,

    Using JDK6 I would like to disable user to drag and drop columns Read the JTableHeader API. You can prevent reordering of the columns.
    and change the default layout of my JTables.How do you expect us to answser this??? What do you mean by changing the layout? Whats wrong with row and column and what do you want to change it to?

  • How to Create Table Using Column Drag and Drop Feature

    Hi:
    I am new to Oracle SQL dev Data Modeler tool and would like to know if there is a way to create a new table by re-using the existing columns or column groups. The idea is to maintain consistency and save table design time. If columns created previously can be re-used and require drag and drop of column in the right pane, then only new columns need to be manually created.
    Any thoughts on this will be appreciated.
    Thanks!

    Hi Kent
    I checked out the video and tried it in Oracle designer, it works and works great!
    My other question is that I may have several set of columns that I may want to group depending on the table requirements. Can I have multiple templates and choose which one to apply to?
    Also, how do I choose the table where the table template needs to be applied. As I may be interested in applying the table template to selected tables only.
    Thanks
    Edited by: user648132 on Feb 20, 2012 10:47 AM

  • Multiple Item Drag and Drop

    I'm working on an application where I need multiple item DnD between JTrees and JTables. I'm using Java 1.4.1
    I have the basics of multiple item DnD working, by creating Transferable classes that contain a collection of items.
    The problem I have is when I drag a multiple selection within a JTree (i.e. DragSource and DropTarget are the same) then my call to event.getCurrentDataFlavors() in my dragOver(DropTargetDragEvent event) method is not returning any data flavours unless I drag over to another JTree. If I now drag back over to the source JTree (so that DragSource and DropTarget are again the same) as if by magic I now get DataFlavours whilst dragging over the source container.
    This is driving me nuts! :-)
    Has anybody else seen this and do they have a solution?

    I have the same problem here.
    When I try to perform drag and drop in a JTree (DragSource and DropTarget are the same), calling event.getCurrentDataFlavors() in the dragOver(DropTargetDragEvent event) method in the DropTargetListener returns me nothing!!
    However, the call of event.getCurrentDataFlavors() in the
    drop(DropTargetDropEvent event) does return me the correct
    information.
    On the doc, the DropTargetDragEvent.getCurrentDataFlavors()
    should mimic DropTargetDropEvent.getCurrentDataFlavors().
    So, I suppose both functions should work in the same way
    properly.
    Is there anything wrong with my understanding or is that a bug
    of the Java dnd?

  • Drag n Drop in JTable with AbstractTableModel

    Dear Experts,
    I would like to drag and drop rows in a JTable. For example, if I have 6 rows in a JTable based on an AbstractTableModel and if I am trying to drag row number 5 and wish to drop it at row number 2, then the 5th row which was dragged should be pasted as 3rd row and the rows 3 and 4 should be rearranged (ie, moved one place down).
    Can anyone help me in achieving this? Any readymade code available? :-)
    I tried running the code in the Java Tutorial in the link
    http://java.sun.com/docs/books/tutorial/uiswing/examples/dnd/index.html
    but, this didnt help as it was mainly for a DefaultTableModel I guess. Also, when I used the StringTransferHandler and TableTransferHandler, I was able achieve just copying the dragged row and pasting at the dropped row. The row rearrangement was not functioning.
    Pls Help...
    Thanks & Regards
    Irfaan

    I have 6 rows in a JTable based on an AbstractTableModelDo you know what "Abstract" means? I suggest you look it up in your Java text book.
    You are not using the AbstractTableModel, you are using a TableModel that extends AbstractTableModel.
    but, this didnt help as it was mainly for a DefaultTableModel That is exactly why you should be using the DefaultTableModel since it supports the concept of moving rows. If you want to use a custom TableModel, then you need to implement the concept of moving rows yourself. So why write a custom TableModel when this has already been done for you??

  • Drag n Drop In Jtable

    Hiii Guys......
    I need a code for drag n drop feature in JTable.
    i need that, i should be able to interchange value of two cells in the same Jtable with drag n drop..... with values getting changed in the database also......

    What code have you written so far?

  • Drag N Drop in JTables

    Hi !
    I have two scenarios
    1) I need to be able to drag and drop rows from a given table to the other table.
    2) I should be able to drag and drop rows with in the same table( This case is same as rearranging the rows with in the table with the help of MouseDragged Event).
    Is this possible using Drag N Drop in swing? Greatly appreciate solutions and online resources which can help me write my custom TransferHandler for the above purposes

    Ok, here's the promised source code
    When the Class is initialized you need to create a couple of objects
              DragSource dragSource = DragSource.getDefaultDragSource() ;
              dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this) ;And you will need the following method
         public void dragGestureRecognized(DragGestureEvent e) {
              String v = (String) getSelectedValue() ;
              e.startDrag(DragSource.DefaultCopyDrop, new StringSelection(v), this) ;
         }or a variation on it. You will of course need the imports and such to support these, but most of it is in the java.awt.dnd package.
    Then in your target you'll need a method to catch the drop ...
         public void drop(DropTargetDropEvent e){
              try{
                   DataFlavor stringFlavor = DataFlavor.stringFlavor ;
                   Transferable tr = e.getTransferable() ;
                   if(e.isDataFlavorSupported(stringFlavor)){
                        String name = (String) tr.getTransferData(stringFlavor) ;
                        e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE) ;
                        Point p = e.getLocation() ;
                        int x = Integer.parseInt(String.valueOf(Math.round(p.getX()))) ;
                        int y = Integer.parseInt(String.valueOf(Math.round(p.getY()))) ;
                        int i = lastScenarioIndex++ ;
                        addDrawingObject(
                             new ScenarioDrawingObject("SCENARIO_" + i, "SCENARIO_" + i, y, x,
                             new SequenceMemberDrawingObject(name, name, 20, 20))) ;
                        resizeContainer() ;
              catch(IOException ioe){
                   ioe.printStackTrace() ;
              catch(UnsupportedFlavorException ufe){
                   ufe.printStackTrace() ;
         }There's a little more to it, but that's the crux of it.
    Cheers.

  • Drag and Drop in JTable never gets DropTargetListener events

    I'm trying to implement Drag/Drop between two JTables. I have adapted the source from the Drag/Drop Tutorial but none of the DropTargetListener events get called. When I try to drag a row from one table to the other, the debug output is as follows:
    beginning drag : ROW 3
    dragsource : dragExit
    dragsource : dragDropEnd
    I'm using JDK 1.3. Any help would be appreciated, here is the source:
    public class DnDTable extends JTable implements DropTargetListener, DragSourceListener, DragGestureListener
    public DnDTable(Object[][] rowData,Object[] columnNames)
    super(rowData,columnNames);
    m_dropTarget = new DropTarget(this,this);
    m_dragSource = new DragSource();
    m_dragSource.createDefaultDragGestureRecognizer(this,DnDConstants.ACTION_MOVE,this);
    public void dragEnter(DropTargetDragEvent event)
    System.out.println("droptarget : dragEnter");
    event.acceptDrag(DnDConstants.ACTION_MOVE);
    public void dragExit(DropTargetEvent event)
    System.out.println("droptarget : dragExit");
    public void dragOver(DropTargetDragEvent event)
    System.out.println("droptarget : dragOver");
    public void drop(DropTargetDropEvent event)
    System.out.println("droptarget : drop");
    try
    Transferable transferable = event.getTransferable();
    // we accept only Strings
    if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor))
    event.acceptDrop(DnDConstants.ACTION_MOVE);
    String s = (String)transferable.getTransferData(DataFlavor.stringFlavor);
    setValueAt(s,rowAtPoint(event.getLocation()),0);
    event.getDropTargetContext().dropComplete(true);
    else
    event.rejectDrop();
    catch(IOException exception)
    exception.printStackTrace();
    System.err.println( "Exception" + exception.getMessage());
    event.rejectDrop();
    catch(UnsupportedFlavorException ufException )
    ufException.printStackTrace();
    System.err.println( "Exception" + ufException.getMessage());
    event.rejectDrop();
    public void dropActionChanged(DropTargetDragEvent e)
    public void dragGestureRecognized(DragGestureEvent event)
    int nDragRow;
    Object object;
    nDragRow = getSelectedRow();
    object = getValueAt(nDragRow,0);
    if (object != null )
    System.out.println("beginning drag:" + object.toString());
    StringSelection text = new StringSelection(object.toString());
    m_dragSource.startDrag(event,DragSource.DefaultMoveDrop,text,this);
    else
    System.out.println("nothing was selected");
    public void dragDropEnd(DragSourceDropEvent event)
    System.out.println("dragsource : dragDropEnd");
    public void dragEnter(DragSourceDragEvent event)
    System.out.println("dragsource : dragEnter");
    public void dragExit(DragSourceEvent event)
    System.out.println("dragsource : dragExit");
    public void dragOver(DragSourceDragEvent event)
    System.out.println("dragsource : dragOver");
    public void dropActionChanged(DragSourceDragEvent event)
    System.out.println("dragsource : dropActionChanged");
    DropTarget m_dropTarget;
    DragSource m_dragSource;

    Hi My friend,
    The code you have took will perfectly works.
    I have an option please try this.
    Instead of DnDConstants.ACTION_MOVE try DnDConstants.ACTION_COPY.
    Lakshmi.

  • Drag and Drop in jtable!

    Hi everybody!
    I want drag some element from some list and drop in some cell in jtable, but i have a problem because this element can use more than one cell, all depends! , the drag moviment seem to work fine between list and the JTable. when the drag cursor is above a row in the JTable, ONLY ONE cell in that row is highlighted, but i want that more than one cell get highlighted and i want put the information in more than one cell.
    Anyone know how to do that?
    thanks in advance
    ps:I am a freshman in foruns, sorry about my english.

    Hi everybody!
    I want drag some element from some list and drop in some cell in jtable, but i have a problem because this element can use more than one cell, all depends! , the drag moviment seem to work fine between list and the JTable. when the drag cursor is above a row in the JTable, ONLY ONE cell in that row is highlighted, but i want that more than one cell get highlighted and i want put the information in more than one cell.
    Anyone know how to do that?
    thanks in advance
    ps:I am a freshman in foruns, sorry about my english.

  • Drag and Drop inside JTable: what draws the 'insert' line during the drag?

    I'm trying to reconfigure a rather complex table with a fair number of custom renderers to include drag & drop of rows for resorting the table. Everything is working great, except that as I drag the rows there is no indication of the current insert point (i.e. the line that appears between rows). When I make a simpler table I see the line... I'm not sure what aspect of my current table is blocking this function. I'm writing in the hope that can someone can direct me to the method(s) responsible for drawing this line.
    Thanks!

    To elaborate a bit for anyone who might read this. I inquired with the Substance developers and they hope to support this feature in v5.1 (which requires SE6), but have no plans to update v4.3 (the last release before a switch to SE6).
    Also, I'd still be grateful for any info pointing me to the Swing methods that draw the drag line.

  • Drag and Drop from JTable

    Using cntl C and cntl V to copy data from a JTable
    into another file
    j2sdk1.4.0 copied the column names along with the data.
    j2sdk1.4.1_04 does not copy the column names anymore.
    Is there any way to get the previous functionality?

    Does anyone use cut and paste to copy data from a JTable to another file?
    I wonder why the new RE-Version doesn't copy the column headers anymore.

  • What does it take to drag and drop a jTable row to a jTextField?

    What kind of Listeners do I need? I have implemented transferListener and overrode createTransferable. But there was nothing responding when I tried to drag a row away. Any other Listener do I need to implement?

    For better help sooner, post an SSCCE.

  • Disable JTable Column dragging?

    How do you disallow the user from moving the order of your columns in a JTable? They are able to select data within the column, but I don't want them to change the order of the columns (drag and drop the columns). Thanks for any help/suggestions in advance. --Dean                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    JTable table = new JTable(...);
    JTableHeader header = table.getTableHeader();
    header.setReorderingAllowed(false);Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

Maybe you are looking for

  • Deleting list for sale order

    Hi Guru’s How can get the deleting list for sale order?    Useful answer duly rewarded back. Regards, Devendra

  • Display images in original dimensions

    Hi, I have a report that contains the blob field from the database to display the images, All i need is to display the images in their original sizes that is if the image is big display it as big and vice versa I tried an option of can grow but it do

  • CD burn error 4701

    I have tried to burn a playlist using ITunes to CD as I've done dozens of times. I insert a blank CD and the burning process begins. After a period of approx. 8 or 9 tracks the burning process self cancels, then a message 'an unknown error has occure

  • Memory Leak in NK.exe

    Hi All, OS: Windows Embedded Compact 7 with updates till Feb 2015. Hardware: AM335x based  Applications running: one serial port application and one tcpclient and tcpserver apps. all are managed (C#) applications I am facing memory leak issue with ou

  • How to automatically open last opened document when Reader launches?

    How to automatically open last opened document when Reader launches?