|
|
|
Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4
|
|
|
作者: 来源:网络文章
时间:2005-12-16 22:39:28
|
|
|
|
|
|
|
Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(15) The following sample program combines all of these operations. There is one draggable text label, one draggable image label, one droppable image label, and a text field for dropping the text. import Java.awt.*;import Java.awt.event.*;import Java.awt.datatransfer.*;import Javax.swing.*;public class DragTwo {public static void main(String args[]) { JFrame frame = new JFrame("Second Drag"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); Toolkit kit = Toolkit.getDefaultToolkit(); final Clipboard clipboard =kit.getSystemClipboard(); JTextField tf = new JTextField(); contentPane.add(tf, BorderLayout.NORTH); Icon icon = new ImageIcon("scott.jpg"); JLabel label1 = new JLabel(icon); label1.setTransferHandler(new ImageSelection()); MouseListener pressListener = new MouseAdapter() {public void mousePressed(MouseEvent e) {JComponent comp = (JComponent)e.getSource();TransferHandler handler =comp.getTransferHandler();handler.eXPortAsDrag (comp, e, TransferHandler.COPY);} }; label1.addMouseListener(pressListener); TransferHandler handler = new TransferHandler("text"); JLabel label2 = new JLabel("Drag Me"); label2.setTransferHandler(handler); label2.addMouseListener(pressListener); JPanel panel = new JPanel(); panel.add(label1); panel.add(label2); contentPane.add(panel, BorderLayout.SOUTH); final JLabel dropZone = new JLabel(); dropZone.setTransferHandler(new ImageSelection()); MouseListener releaseListener = new MouseAdapter() {public void mouseReleased(MouseEvent e) {Transferable clipData = clipboard.getContents (clipboard);if (clipData != null) { if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) {TransferHandler handler =dropZone.getTransferHandler();handler.importData(dropZone, clipData); }}} }; dropZone.addMouseListener(releaseListener); JScrollPane pane = new JScrollPane(dropZone); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(400, 400); frame.show();}}
|
|
|
1. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(1)
2. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(2)
3. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(3)
4. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(4)
5. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(5)
6. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(6)
7. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(7)
8. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(8)
9. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(9)
10. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(10)
11. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(11)
12. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(12)
13. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(13)
14. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(14)
15. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(15)
16. Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4(16)
|
|
| 共16页 9 7 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] 8 :>
|
|
Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4 相关文章:
|
Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4 相关软件:
|
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com
|
|
|