tags:

views:

43

answers:

2

How can I show tooltips while performing drag-n-drop. It seems that tooltip display during drag-n-drop operation is disabled or not triggered. I want to use the tooltip to indicate to the user why the drop is being denied.

+1  A: 

You may be able to take advantage of Drop Location Rendering to achieve a similar effect.

trashgod
+1  A: 

The solution that worked for me was to create the tool tip manually inside the TransferHandler. Here is the code I added:

public class TableTransferHandler extends TransferHandler {
    private Popup tipWindow;
    private int tipCol;
    private int tipRow;

    public boolean canImport(TransferHandler.TransferSupport support) {
        ....
        updateDropDeniedTooltip(support, deniedReason)
    }

    private void hideDropDeniedTooltip() {
        if (tipWindow != null) {
            tipWindow.hide();
            tipWindow = null;
        }
    }

    private void updateDropDeniedTooltip(TransferHandler.TransferSupport support, String deniedReason) {
        if (deniedReason != null) {
            JTable.DropLocation dropLocation = (JTable.DropLocation)support.getDropLocation();
            JTable jtable = (JTable)support.getComponent();
            if (tipWindow != null) {
                if (tipRow != dropLocation.getRow() || tipCol != dropLocation.getColumn()) {
                    hideDropDeniedTooltip();
                }
            }
            if (tipWindow == null) {
                tipRow = dropLocation.getRow();
                tipCol = dropLocation.getColumn();
                JToolTip tip = jtable.createToolTip();
                tip.setTipText(result.getReason());
                PopupFactory popupFactory = PopupFactory.getSharedInstance();
                Rectangle cellRect = jtable.getCellRect(tipRow, tipCol, true);
                Point location = jtable.getLocationOnScreen();
                location.x += cellRect.x;
                location.y += cellRect.y;
                tipWindow = popupFactory.getPopup(jtable, tip, location.x, location.y);
                tipWindow.show();
            }
        }
        else {
            hideDropDeniedTooltip();
        }
    }
 }
Ivo Bosticky
+1 for a working example.
trashgod