Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37569 > unrolled thread

How do you update a component when you leave on a drag?

Started byEric Douglas <e.d.programmer@gmail.com>
First post2017-10-13 10:42 -0700
Last post2017-10-16 06:07 -0700
Articles 4 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  How do you update a component when you leave on a drag? Eric Douglas <e.d.programmer@gmail.com> - 2017-10-13 10:42 -0700
    Re: How do you update a component when you leave on a drag? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-10-13 14:04 -0500
      Re: How do you update a component when you leave on a drag? Eric Douglas <e.d.programmer@gmail.com> - 2017-10-13 13:02 -0700
        Re: How do you update a component when you leave on a drag? Eric Douglas <e.d.programmer@gmail.com> - 2017-10-16 06:07 -0700

#37569 — How do you update a component when you leave on a drag?

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-10-13 10:42 -0700
SubjectHow do you update a component when you leave on a drag?
Message-ID<255e35fe-5f4f-4916-89c5-f5d07b74ca3c@googlegroups.com>
I wrote a custom TransferHandler, which is changing the appearance of a custom JTable through it's custom UI.
I put the method call to change the appearance in the canImport method, but this method is only getting called as I drag over the control.  What method should I be updating to tell it I was dragging over that control and have left the bounds of that control so I can restore it's appearance?

[toc] | [next] | [standalone]


#37570

FromKnute Johnson <nospam@rabbitbrush.frazmtn.com>
Date2017-10-13 14:04 -0500
Message-ID<orr2pd$219$1@dont-email.me>
In reply to#37569
On 10/13/2017 12:42, Eric Douglas wrote:
> I wrote a custom TransferHandler, which is changing the appearance of a custom JTable through it's custom UI.
> I put the method call to change the appearance in the canImport method, but this method is only getting called as I drag over the control.  What method should I be updating to tell it I was dragging over that control and have left the bounds of that control so I can restore it's appearance?
> 

Do you want to update it while you are still dragging?  I'm not sure but 
have you tried calling validate() based on the mouse position?  You may 
still have problems in that the EDT is blocked by your drag operation.

Can you make an SSCCE?

-- 

Knute Johnson

[toc] | [prev] | [next] | [standalone]


#37571

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-10-13 13:02 -0700
Message-ID<08b10dcc-e61e-4f55-a0cb-878d64493104@googlegroups.com>
In reply to#37570
On Friday, October 13, 2017 at 3:05:49 PM UTC-4, Knute Johnson wrote:
> On 10/13/2017 12:42, Eric Douglas wrote:
> > I wrote a custom TransferHandler, which is changing the appearance of a custom JTable through it's custom UI.
> > I put the method call to change the appearance in the canImport method, but this method is only getting called as I drag over the control.  What method should I be updating to tell it I was dragging over that control and have left the bounds of that control so I can restore it's appearance?
> > 
> 
> Do you want to update it while you are still dragging?  I'm not sure but 
> have you tried calling validate() based on the mouse position?  You may 
> still have problems in that the EDT is blocked by your drag operation.
> 
> Can you make an SSCCE?
> 
> -- 
> 
> Knute Johnson

I am updating the control while I'm dragging, which works fine while I'm dragging over the JTable.

I set this in my JTable constructor.
setTransferHandler(new MyCustomTransferHandler(this));

Within the transfer handler, I'm using this method to tell the JTable to repaint:
public boolean canImport(final TransferHandler.TransferSupport info) {

This passes through to my custom class, which extends BasicTableUI, which draws a red line between rows showing the drop point.

I'm not seeing any events while the mouse is not over the JTable, and I'm not sure if or where it calls a method I can process that says the mouse exited the JTable.  Any mouse listener on the JTable checking mouseExited doesn't process until the mouse is released.
Now I want to be able to drag from the JTable to a different control, and remove the red line whenever the mouse is not over the JTable.

I'm not sure how easy that is, but I'll try writing an SSCCE if that's the only way to figure this out.

[toc] | [prev] | [next] | [standalone]


#37573

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-10-16 06:07 -0700
Message-ID<77d5a7ae-33a3-470f-99cd-1fa68c60c6e2@googlegroups.com>
In reply to#37571
On Friday, October 13, 2017 at 4:02:32 PM UTC-4, Eric Douglas wrote:
> > Do you want to update it while you are still dragging?  I'm not sure but 
> > have you tried calling validate() based on the mouse position?  You may 
> > still have problems in that the EDT is blocked by your drag operation.
> > 

My TransferHandler doesn't seem to be aware of when it leaves the JTable, only processing methods while it's over the JTable, so I traced through some of the javax.swing.TransferHandler methods which led me to this.
My JTable has a class variable INSERTROW which my TableUI checks to draw a red line between rows to show where to drop.  I tested overriding the following method which seems to work.  For the test I just made a new anonymous listener, though I'm thinking I should keep one as a private static variable.


     @Override
     public void setDropTarget(final DropTarget dt) {
          super.setDropTarget(dt);
          if (dt != null) {
               try {
                    dt.addDropTargetListener(new DropTargetListener() {

                         @Override
                         public void dragEnter(DropTargetDragEvent dtde) {
                         }

                         @Override
                         public void dragOver(DropTargetDragEvent dtde) {
                         }

                         @Override
                         public void dropActionChanged(DropTargetDragEvent dtde) {
                         }

                         @Override
                         public void dragExit(DropTargetEvent dte) {
                              INSERTROW = -1;
                              fireTableDataChanged();
                         }

                         @Override
                         public void drop(DropTargetDropEvent dtde) {
                         }
                         
                    });
               } catch (TooManyListenersException e) {
                    // ??
                    e.printStackTrace();
               }
          }
     }

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web