zoukankan      html  css  js  c++  java
  • e742. 加入标签的可拖动能力

    This example demonstrates how to modify a label component so that its text can be dragged and dropped to another component.

        // Create a label
        JLabel label = new JLabel("Label Text");
        
        // Specify that the label's text property be transferable; the value of
        // this property will be used in any drag-and-drop involving this label
        final String propertyName = "text";
        label.setTransferHandler(new TransferHandler(propertyName));
        
        // Listen for mouse clicks
        label.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent evt) {
                JComponent comp = (JComponent)evt.getSource();
                TransferHandler th = comp.getTransferHandler();
        
                // Start the drag operation
                th.exportAsDrag(comp, evt, TransferHandler.COPY);
            }
        });
    
    Related Examples
  • 相关阅读:
    Notepad++
    pycharm
    pygame游戏开发-简介
    白月黑羽Python在线教程
    Selenium Web自动化 原理
    Web自动化
    Web自动化
    转:Android开发环境搭建
    Android系统架构说明介绍
    Enjoy Android
  • 原文地址:https://www.cnblogs.com/borter/p/9596126.html
Copyright © 2011-2022 走看看