Drag the component from one cell to another cell within JTable

Hi All,
I have one requirement to drag the component from JList to JTable cell. I am able to do it but once if i drag the component from list to table cell, table accepting the drop after this i am unable to move the same component from one cell to another cell within the table.
Any advice.
I have used the following logic for JTable and JList is drag enabled.
DefaultTableModel tableModel=new DefaultTableModel(
            new Object [][] {
                {null, null, null, null,null,null,null},
                {null, null, null, null,null,null,null},
                {null, null, null, null,null,null,null},
                {null, null, null, null,null,null,null}
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4","Title 5","Title 6","Title 7"
        JTable table = new javax.swing.JTable(){
            public boolean isCellEditable(int row, int column)
                return false;
        table.setModel(tableModel);
        table.setDragEnabled(true);
        table.setDropMode(DropMode.INSERT);
        table.setTransferHandler(new TransferHandler(){
            public boolean canImport(TransferHandler.TransferSupport info){
                if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)){
                    return false;
                return true;
            public boolean importData(TransferSupport support) {
                if (!support.isDrop()) {
                    return false;
                if (!canImport(support)) {
                    return false;
                JTable table=(JTable)support.getComponent();
                DefaultTableModel tableModel=(DefaultTableModel)table.getModel();
                // fetch the drop location
                JTable.DropLocation dl = (JTable.DropLocation)support.getDropLocation();
                int row = dl.getRow();
                int col=dl.getColumn();
                // fetch the data and bail if this fails
                String data;
                try {
                    data = (String)support.getTransferable().getTransferData(DataFlavor.stringFlavor);
                } catch (UnsupportedFlavorException e) {
                    return false;
                } catch (IOException e) {
                    return false;
                calendarTableModel.setValueAt(data, row, col);
                return true;
        });Thanks & Regards,
Maadhav.
Edited by: maadhav on Jun 23, 2009 12:29 AM

Hi All,
I fixed this issue with some additional logic which allow me to drag and drop the string component from one cell to another cell within in the JTable.
I am attaching the new logic here, if any one needs use it.
DefaultTableModel tableModel=new DefaultTableModel(
            new Object [][] {
                {null, null, null, null,null,null,null},
                {null, null, null, null,null,null,null},
                {null, null, null, null,null,null,null},
                {null, null, null, null,null,null,null}
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4","Title 5","Title 6","Title 7"
        JTable table = new javax.swing.JTable(){
            public boolean isCellEditable(int row, int column)
                return false;
        table.setModel(tableModel);
        table.setDragEnabled(true);
        table.setDropMode(DropMode.USE_SELECTION);
        table.setTransferHandler(new TransferHandler(){
          public int getSourceActions(JComponent c) {
                return DnDConstants.ACTION_COPY_OR_MOVE;
            public Transferable createTransferable(JComponent comp)
                JTable table=(JTable)comp;
                int row=table.getSelectedRow();
                int col=table.getSelectedColumn();
                String value = (String)table.getModel().getValueAt(row,col);
                StringSelection transferable = new StringSelection(value);
                table.getModel().setValueAt(null,row,col);
                return transferable;
            public boolean canImport(TransferHandler.TransferSupport info){
                if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)){
                    return false;
                return true;
            public boolean importData(TransferSupport support) {
                if (!support.isDrop()) {
                    return false;
                if (!canImport(support)) {
                    return false;
                JTable table=(JTable)support.getComponent();
                DefaultTableModel tableModel=(DefaultTableModel)table.getModel();
               JTable.DropLocation dl = (JTable.DropLocation)support.getDropLocation();
                int row = dl.getRow();
                int col=dl.getColumn();
                String data;
                try {
                    data = (String)support.getTransferable().getTransferData(DataFlavor.stringFlavor);
                } catch (UnsupportedFlavorException e) {
                    return false;
                } catch (IOException e) {
                    return false;
                tableModel.setValueAt(data, row, col);
                return true;
        });Thanks & Regards,
Maadhav..
Edited by: maadhav on Jun 23, 2009 5:26 AM
Edited by: maadhav on Jun 23, 2009 5:28 AM

Similar Messages

  • I would like to copy all the songs from one Ipod into another. All the songs are into my Itunes account, I tried to drag and drop the songs from the old Ipod to the new one but it doesn't work. Is there a way to do it ?

    Hello everybody,
    I would like to copy all the songs from one Ipod into another. All the songs are into my Itunes account, I tried to drag and drop the songs from the old Ipod to the new one but it doesn't work. Is there a way to do it ?
    I share one Itunes account with other people from my family and one person would like to keep the same songs on the new Ipod as the ones which were on the old one.
    Thanks in advance for your answer.
    Yan

    Hello Chris,
    Thanks for your answer. I was hoping for an easier answer. Too bad there is no drag and drop solution, it would have been much easier.
    Thanks for answering so fast.
    Bye.
    Yan

  • Why doesn't the original document I'm dragging and dropping from one folder to another move?

    Why doesn't the original document I'm dragging and dropping from one folder to another move?
    What's happening is the computer is creating a duplicte of the document and placing it in the new location with a new creation date.  The original document I wanted to drag and drop into a new location remains where it started as the "original" document and the new copy has this little arrow protruding up from the lower left of its icon.
    At first I thought it was an alias, but it's a copy of the document I thought I was dragging and dropping.
    What gives here?
    Steve

    That arrow indicates it is a linik to the original, though. This happens if you wish to drag files, for which you do not have permissions to do this operation, e.g. from Library or System folder. I am pretty sure you do not accomplish this operation from/to folders like Desktop or Documents; if so, there is a problem with your system.

  • Drag a column from one position to another within the table.

    Hello All,
    In Web Dynpro Java, Is it possible to provide user a functionality with which he/she can move the columns of a table from one position to another ?
    Scenario : Users want flexibility to decide the location the columns as per their convinience while they are working with the application.
    So can we develop some code or can we use some UI element so that user is able to drag a column from one position to another within the table.
    Regards
    Mrinalini.

    Hi Mrinalini,
    Yes this is possible you can try to move the table columns (Change the order). for this you don't need to do additional coding or property change its a default property for web Dynpro java tables.
    Regards
    Jeetendra

  • When dragging a thumbnail from one place to another, the origional thumbmail ends up in other locations.  Sometimes the same thumbnail covers up other thimbmails.

    When dragging a thumbnail from one place to another, the origional thumbmail ends up in other locations.  Sometimes the same thumbnail covers up other thimbmails.

    Hi christophers37215878
    Please elaborate your issue.
    What exactly are you trying to achieve?
    Which Adobe Product or service are you referring to?
    Can you please provide the screenshot?
    Regards,
    Rahul

  • I am trying to drag and drop one page of a .pdf into another .pdf in Acrobat Reader.  I used to be able to drag and drop from one .pdf to another.

    I am trying to drag and drop one page of a .pdf into another .pdf in Acrobat Reader.  I used to be able to drag and drop from one .pdf to another.

    If you could drag and drop pages before, it wasn't in Reader. You no doubt had Adobe Acrobat (Pro or Standard) which shouldn't be confused with Adobe Acrobat Reader. They recently added Acrobat to the name of Adobe Reader so the confusion about which product you had and/or have is understandable.

  • How to move CRM_UI_FRAME component from one box to another box

    Hi All,
    Need help about this task.
    Background:
    - CRM Dev Box
    - CRM QC Box
    - CRM Prod Box
    Problem:
    - CRM_UI_FRAME component on the QC Box is not working properly. When we are going to the BSP Workbench, an error comes out that there is an unclosed tag; '>' or '/>' expected entity: "<<document>>" Offset : 0000003376 Error Severity: error.
    - BSPWD_BASICS/WorkAreaHostViewSet is not loaded
    - This problem never occurs on both Dev and Prod Box
    Our Solution:
    - To copy the whole CRM_UI_FRAME component from Dev to QC
    Our Question
    - Is the solution possible?
    - If it is, how could we transfer/copy the whole CRM_UI_FRAME or any component from one box to another box
    - Could we just attach this to a transport? Or is this a BASIS task?
    - Other suggestions on how to do this?
    Thanks in advance!
    Regards,
    Marc

    Hi,
    Please ensure to read note #[1540435 |http://service.sap.com/sap/support/notes/1540435]and to decide which update strategy/scenario you
    need and in the "[SLD Planning Guide|http://www.sdn.sap.com/irj/sdn/nw-sld?rid=/library/uuid/e0a1a8fb-0527-2a10-f781-8b67eab16582]".
    You should ensure that your CIM Model and CR Content on your SLD are updated as
    per SAP note [669669 |http://service.sap.com/sap/support/notes/669669]on both SLDs.
    Regards,
    Aidan

  • FM to move Component from one IBase to another ?

    Hi All,
    We need to move a Component from one IBase to another (without deleting it).
    How do we do this ? Is there any FM / BAPI for the same ?
    Regards,
    Ashish

    FM - CRM_IBASE_COMP_MOVE

  • How to transfer the logins from one instance to another instance in sql2008r2

    how to transfer the logins from one instance to another instance in sql2008r2

    Hi Ganesh,
    According to your description, you want to know how to transfer the logins from one instance to another instance for SQL Server 2008 R2. To do this, besides dave’s post, you could also use
    'Copy Database Wizard' in SQL Server Management Studio, or the component
    'transfer Login task' in SQL Server Integration Services.
    Regards,
    Michelle Li

  • Photoshop: how to drag a layer from one tab to another?

    Hello, I am trying to drag a layer from one tab to another in Photoshop and I was able to do this less than 1/2 hour ago and now it will not drag. I have closed the program, restarted my computer, everything and it will not drag. What is wrong???

    Does this work for you?
    Document A - left click to select the layer to be copied, then Layer command in the menu bar (or right click in the Layers panel) > Duplicate Layer
    In the Duplicate Layer dialogue box, Destination: Document, select the open file to which you want to copy the layer from the dropdown menu
    Click OK

  • Transfer data in the Ztable from one client to another client in a same ser

    Hi all,
    How can i transfer or move data in the Ztable from one client to another client in a same server .
    Thanks
    Ajay

    hi,
    create a transport request (Workbench type) and add the following line into the transport request:
    R3TR TABU name_of_table
    save and doubleclick this line and enter the table keys for the required entries (if you need all antries: client and an asterisk will do).
    When it is done save again, release the transport and ask basis to import into target client (or you can do on your own in SCC1 transaction)
    hope this helps
    ec

  • How we can get the values  from one screen to another screen?

    hi guru's.
         how we can get the values  from one screen to another screen?
              we get values where cusor is placed but in my requirement i want to get to field values from one screen to another screen.
    regards.
      satheesh.

    Just think of dynpros as windows into the global memory of your program... so if you want the value of a field on dynpro 1234 to appear on dynpro 2345, then just pop the value into a global variable (i.e. one defined in your top include), and you will be able to see it in your second dynpro (assuming you make the field formats etc the same on both screens!).

  • Passing the values from one pgm to another pgm (Calling pgm has no sel scr)

    Hi gurus,
    In my requirement i need to pass the values from one program to another program.
    I am using SUBMIT statement . But , the program which i am calling has no selection screen.
    So how can i pass the values?
    Please help me ASAP.
    Regards,
    Bhanu.R

    Export your internal tables or work areas to a memory id in ur program before u use submit.
    Then in second pgm you have to import from memory id given above.
    example.
    EXPORT gs_header FROM gs_header to memory id 'HEADER'.
    EXPORT gt_item FROM gt_item to memory id 'ITEM'.
    SUBMIT YFIIN_DISHC_MAILREPORT EXPORTING LIST TO MEMORY AND RETURN.
    In your second pgm you can write
    import gs_header TO gs_header from MEMORY id 'HEADER'.
    import gt_item TO gt_item from MEMORY id 'ITEM'.

  • How can you move the objects from one server to another?

    how can you move the objects from one server to another?

    Hi,
    Collecting objects for Transporting
    1. rsa1->transport connection
    2. left panel choose 'object type', middle panel choose 'infocube' and 'select objects'
    3. then choose your infocube and 'transfer'
    4. will go to right panel, choose collection mode 'manual' and grouping only 'necessary objects'
    5. after objects collection finished, create request
    6. If they are $TMP, then change the package.
    7. When you click the Save on the change package, it will prompt for transport. Here you can provide an existing open transport request number, or if you like here itself you can create a new one.
    8. You can check the request in SE09 to confirm.
    Releasing Transport Request  
    Lets say you are transporting from BWD to BWQ
    Step 1: In BWD go to TCode SE10
    Step 2: Find the request and release it (Truck Icon or option can be found by right click on request #)
    Note: First release the child request and then the parent request
    Steps below are to import transport (generally done by basis )
    Step 1: In BWQ go to Tcode STMS
    Step 2: Click on Import queue button
    Step 3: Double Click on the line which says BWQ (or the system into which transport has to be imported)
    Step 4: Click on refresh button
    Step 5: High light the trasnport request and import it (using the truck icon)
    Transport
    http://help.sap.com/saphelp_nw2004s/helpdata/en/b5/1d733b73a8f706e10000000a11402f/frameset.htm
    http://help.sap.com/saphelp_nw70/helpdata/en/0b/5ee7377a98c17fe10000009b38f842/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/media/uuid/224381ad-0701-0010-dcb5-d74236082bff
    Hope this helps.
    thanks,
    JituK

  • How can I pass the photos from one iphone to another?

    how can I pass the photos from one iphone to another?

    Use the Beaming feature. See the info at the ? In iPhoto for iOS.

Maybe you are looking for

  • Itunes on my pc will not open or do anything.

    I have been trying to open Itunes on my desktop pc for days and nothing happens, everytime I click on it nothing happens, nothing comes up, no error messages or anything, tried to open in safemode and nothing happened. My computer and all my other pr

  • Export a single calendar from iCal

    How do I export a single calendar from iCal? I have several calendars but only want to send someone one of them.

  • Log-File missing

    Hello, I´ve done a stupid mistake, I hope anybody can help me now: I have reorganized the hard disks of my pc and unfortunally formatted a seemingly unessential disk. Now, my Basis-System (MaxDB 7.6.00.35) is crashing when starting the database: VOLU

  • How to create a briefing book in Shared Folders

    Hello, Firstly, can the subject of this thread be achieved? I am able to create a briefing book (within My Briefing Books) and use delivers to deliver it to myself. However, I receive the access denied error message when trying to send the same BB to

  • Audio not in sync with picture

    I am using the Creative Live webcam. When ever I record a video the picture looks ok, but isn't synched up with the audio. I am not sure what the settings should be by default, and I can't seem to find the right codex to make them match up. See an ex