我的动作总是发送NONE而不是MOVE

时间:2019-05-02 09:19:02

标签: java drag-and-drop move

我想移动面板(StickerView)。我使用了StickerView的3个构造函数,带有linkMission的StickerView,另一个带有Mission标题的构造器和另一个空的。当我将StickerView(linkMission)移至StickerView(linkMission),而不是将StickerView(linkMission)移至StickerView(空)时,正在移动工作。动作为“无”,我要移动(动作== 2)。

这里,面板的构造函数:

    public StickerView(HomeView homeView, LinkMission linkMission, String missionType, MyGlassPane glass,
            int indexPlanning) {
        this.missionType = missionType;
        this.homeView = homeView;
        this.linkMission = linkMission;
        this.indexPlanning = indexPlanning;
        setDateStickerView(linkMission.getDatePlanning());
        ctrl = new StickerCtrl(this);
        this.addMouseListener(new MouseGlassListener(glass, this));
        this.addMouseMotionListener(new MouseGlassMotionListener(glass));
        this.setTransferHandler(new MyTransferHandler());

    }

我的问题位于MyTransferHandler的类中,因为操作始终等于NONE:

protected void exportDone(JComponent c, Transferable t, int action){

    if (action == MOVE) {
    }

我在这里定义了MOVE(MyTransferHandler类):

public int getSourceActions(JComponent c) {
        return MOVE;
    }

在我的控制器(MouseGlassListener)中,当我释放组件时:

public void mouseReleased(MouseEvent event) {
        JComponent lab = (JComponent) event.getSource();
        TransferHandler handle = lab.getTransferHandler();

        if (handle != null) {
            handle.exportAsDrag(lab, event, TransferHandler.MOVE);
            Component composant = event.getComponent();
            Point location = (Point) event.getPoint().clone();
            SwingUtilities.convertPointToScreen(location, composant);
            SwingUtilities.convertPointFromScreen(location, myGlass);
            myGlass.setLocation(location);
            myGlass.setImage(null);
            myGlass.setVisible(false);
        }

    }

0 个答案:

没有答案