展示各种界面数据传输 : 拖放 « 图形用户界面 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » 图形用户界面 » 拖放屏幕截图 
展示各种界面数据传输
展示各种界面数据传输
 
/*
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.com/, 1996-2002.
 * All rights reserved. Software written by Ian F. Darwin and others.
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 
 * Java, the Duke mascot, and all variants of Sun's Java "steaming coffee
 * cup" logo are trademarks of Sun Microsystems. Sun's, and James Gosling's,
 * pioneering role in inventing and promulgating (and standardizing) the Java 
 * language and environment is gratefully acknowledged.
 
 * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&T, for
 * inventing predecessor languages C and C++ is also gratefully acknowledged.
 */

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.TransferHandler;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Demonstrate various aspects of Swing "data transfer".
 
 @author Ian Darwin, http://www.darwinsys.com
 @author Jonathan Fuerth, http://www.SQLPower.ca
 */
public class Transfer extends JFrame {
  public static void main(String[] args) {
    new Transfer().setVisible(true);
  }

  private JTextField tf;

  private JLabel l;

  private JComboBox propertyComboBox;

  public Transfer() {

    // Establish the GUI
    Container cp = new Box(BoxLayout.X_AXIS);
    setContentPane(cp);
    JPanel firstPanel = new JPanel();
    propertyComboBox = new JComboBox();
    propertyComboBox.addItem("text");
    propertyComboBox.addItem("font");
    propertyComboBox.addItem("background");
    propertyComboBox.addItem("foreground");
    firstPanel.add(propertyComboBox);
    cp.add(firstPanel);
    cp.add(Box.createGlue());

    tf = new JTextField("Hello");
    tf.setForeground(Color.RED);
    tf.setDragEnabled(true);
    cp.add(tf);

    cp.add(Box.createGlue());

    l = new JLabel("Hello");
    l.setBackground(Color.YELLOW);
    cp.add(l);

    cp.add(Box.createGlue());

    JSlider stryder = new JSlider(SwingConstants.VERTICAL);
    stryder.setMinimum(10);
    stryder.setValue(14);
    stryder.setMaximum(72);
    stryder.setMajorTickSpacing(10);
    stryder.setPaintTicks(true);

    cp.add(stryder);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500300);

    // Add Listeners and Converters
    setMyTransferHandlers((StringpropertyComboBox.getSelectedItem());

    // Mousing in the Label starts a Drag.
    MouseListener myDragListener = new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        JComponent c = (JComponente.getSource();
        TransferHandler handler = c.getTransferHandler();
        handler.exportAsDrag(c, e, TransferHandler.COPY);
      }
    };
    l.addMouseListener(myDragListener);

    // Selecting in the ComboBox makes that the property that is xfered.
    propertyComboBox.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ce) {
        JComboBox bx = (JComboBoxce.getSource();
        String prop = (Stringbx.getSelectedItem();
        setMyTransferHandlers(prop);
      }
    });

    // Typing a word and pressing enter in the TextField tries
    // to set that as the font name.
    tf.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        JTextField jtf = (JTextFieldevt.getSource();
        String fontName = jtf.getText();
        Font font = new Font(fontName, Font.BOLD, 18);
        tf.setFont(font);
      }
    });

    // Setting the Slider sets that font into the textfield.
    stryder.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        JSlider sl = (JSliderevt.getSource();
        Font oldf = tf.getFont();
        Font newf = oldf.deriveFont((floatsl.getValue());
        tf.setFont(newf);
      }
    });

  }

  private void setMyTransferHandlers(String s) {
    TransferHandler th = new TransferHandler(s);
    tf.setTransferHandler(th);
    l.setTransferHandler(th);
  }
}


           
         
  
Related examples in the same category
1. 树:拖放树:拖放
2. 拖放拖放
3. 添加图像拖拽行为
4. 拖拽文件拖拽文件
5. DragSource Test DragSource Test
6. DropTarget Test DropTarget Test
7. 图像传输试验图像传输试验
8. MimeClipboard试验MimeClipboard试验
9. 文件树拖拽目标文件树拖拽目标
10. 文件树拖曳来源文件树拖曳来源
11. 编辑器拖曳目标4编辑器拖曳目标4
12. 拖曳树拖曳树
13. JLabel Drag Source JLabel Drag Source
14. 拖拽面板拖拽面板
15. 编辑器拖拽目标3编辑器拖拽目标3
16. 编辑器拖拽目标编辑器拖拽目标
17. 编辑器拖拽目标2编辑器拖拽目标2
18. JTextArea类允许TransferableColor对象JTextArea类允许TransferableColor对象
19. 转让彩色
20. 彩色拖曳来源
21. 组件拖放文件到树组件拖放文件到树
22. 试验DragGesture类和JList试验DragGesture类和JList
23. TransferHandler和JTextAreaTransferHandler和JTextArea
24. 拖放:文本拖放:文本
25. 拖曳:JList拖曳:JList
26. JDK 1.4组件拖放JDK 1.4组件拖放
27. 拖放: JList和列表框拖放: JList和列表框
28. DnD (drag and drop)JTree code DnD (drag and drop)JTree code
29. 下拉:文本下拉:文本
30. 拖放:文本2拖放:文本2
31. Label DnD (Drag and Drop) Label DnD (Drag and Drop)
32. LabelDnD2允许颜色拖拽LabelDnD2允许颜色拖拽
33. Drag List Demo Drag List Demo
34. Drag Picture Demo
35. 拖拽演示拖拽演示
36. 拖动颜色演示拖动颜色演示
37. 拖动文件演示拖动文件演示
38. Drag Picture Demo 2
39. 拖动TextField的颜色演示拖动TextField的颜色演示
40. BasicDnD (拖拽)BasicDnD (拖拽)
41. 拖放图标:使用一个图标属性。
42. 执行拖放功能
43. 在应用程序探测拖动发起的姿态
44. 制作组件拖动
45. 使用和设置文字系统剪贴板
46. 使用拖放以重新排序清单
47. 创建一个拖曳源来拖拽对象。
48. 实施DragGestureListener
49. 逗号分隔的文本将插入到两个或两个以上的列。
50. TransferHandler subclass wraps another TransferHandler and delegates most of its operations to the wrapped handler
51. 在JTextArea设置文本拖放
52. 内置拖放支持:利用TransferHandler类
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.