⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intro.html

📁 jsf、swing的官方指南
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<p><li>Clipboard transfer via cut/copy and paste.    The following diagrams illustrate the Java portion of the    cut/copy and paste operations:<p><p><center><IMG SRC="../../figures/uiswing/dnd/dndprocess2.gif" WIDTH="485" HEIGHT="103" ALIGN="BOTTOM" ALT="Cut/Copy Illustration"></center></p><p><p><center><IMG SRC="../../figures/uiswing/dnd/dndprocess3.gif" WIDTH="486" HEIGHT="104" ALIGN="BOTTOM" ALT="Paste Illustration"></center></p></ul><p>The arrows in the preceding diagrams show the path of the data.<p>In a nutshell, a data transfer begins by bundling the datainto a package, called a <code>Transferable</code>.Then the component provides an object, called a<code>TransferHandler</code> that extracts the data fromthe <code>Transferable</code>.<p>Many Swing components provide out-of-the-box support for transferringdata, as shown in the following table:<p><table summary="Data Transfer Support" border=1><caption><a name=defaultSupport>Data Transfer Support</a></caption><tr><th>Component</th>    <th>Drag*<br>Copy</th>    <th>Drag*<br>Move</th>    <th>Drop</th>    <th>Cut</th>    <th>Copy</th>    <th>Paste</th></tr><tr><th align=left><code>JColorChooser**</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><th align=left><code>JEditorPane</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td></tr><tr><th align=left><code>JFileChooser***</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td></tr><tr><th align=left><code>JFormattedTextField</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td></tr><tr><th align=left><code>JList</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td></tr><tr><th align=left><code>JPasswordField</code><td align=center><i>n/a</i></td><td align=center><i>n/a</i></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><i>n/a</i></td><td align=center><i>n/a</i></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td></tr><tr><th align=left><code>JTable</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td></tr><tr><th align=left><code>JTextArea</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td></tr><tr><th align=left><code>JTextField</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></tr><tr><th align=left><code>JTextPane</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td></tr><tr><th align=left><code>JTree</code><td align=center><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td><p><center><IMG SRC="../../figures/uiswing/../../images/check.gif" WIDTH="12" HEIGHT="12" ALIGN="BOTTOM" ALT="checked"></center></p></td><td>&nbsp;</td></table>&nbsp;&nbsp;*Enabled by invoking <code>component.setDragEnabled(true)</code>on the component.<br>&nbsp;**Imports and exports data of type <code>java.awt.Color</code>.<br>***Exports both a list of filenames as <code>java.io.File</code>objects (preferred) and as strings for those componentsthat do not accept <code>File</code> objects.  The <em>FileName</em> text field in the file chooser accepts strings;the browser in the file chooser does not accept data.Note that as of release 1.4, clipboard copy from a <code>JFileChooser</code>is broken and actually causes the file to be moved when itis pasted.  You may want to watch bug<a class="OutsideLink" target="_blank" href="http://developer.java.sun.com/developer/bugParade/bugs/4915992.html">#4915992</a>.<p>The data transfer mechanism is built in to every <code>JComponent</code>. For all the componentswith an empty space in the preceding table only a smallamount of code is needed to customize the support.Support can easily be added to <code>JComponent</code>s not listed in the table so theycan fully participate in data transfer.<p>The rest of this section covers the following topics:<ul><li><a href=#cursorIcons>A Visual Guide to Drag and Drop Cursor Icons</a><li><a href=#intro>Introduction to Data Transfer Support</a><li><a href=#label>A Simple Example: Adding DnD to JLabel</a><li><a href=#complex>Extending Default DnD Support</a><li><a href=#dataFormat>Specifying the Data Format</a><li><a href=#customImport>Importing a New Flavor: Color</a><li><a href=#replacingSupport>Replacing Default Support: Color and Text</a><li><a href=#importFiles>Importing a New Flavor: Files</a><li><a href=#customComp>Data Transfer with a Custom Component</a><li><a href=#customFlavor>Data Transfer with a Custom DataFlavor</a><li><a href=#cut>Adding Cut/Copy/Paste Support</a><li><a href=#api>The Data Transfer API</a><li><a href=#eg>Examples that Use Data Transfer</a></ul></blockquote><a name=cursorIcons><h2>A Visual Guide to Drag and Drop Cursor Icons</h2></a><blockquote><p>Before delving into drag and drop further, it's usefulto take a look at the various cursor icons you mayencounter when initiating a drag operation.We expect the Solaris and Linux cursor iconsto change for release 1.5, but here is a guideas of release 1.4:<a name=cursorIconTable><h4 align=center>Cursor Icons for Drag and Drop</h4></a><table align=center border=1><tr><th align=left>Microsoft<br>Windows</th><th align=left>Solaris/<br>Linux</th><th align=left>Description</th></tr><tr valign=center><td align=center><IMG SRC="../../figures/uiswing/dnd/win32_CopyDrop.gif" WIDTH="23" HEIGHT="32" ALT="Copy cursor icon for Windows, the component below accepts the drop."></td><td align=center><IMG SRC="../../figures/uiswing/dnd/motif_CopyDrop.gif" WIDTH="32" HEIGHT="32" ALT="Copy cursor icon for Linux/Solaris, the component below accepts the drop."></td><td>Copy.The component underneath accepts this type of data.</td></tr><tr valign=center><td align=center><IMG SRC="../../figures/uiswing/dnd/no.gif" WIDTH="20" HEIGHT="20" ALT="Copy cursor icon for Windows, the component below won't accept."></td><td align=center><IMG SRC="../../figures/uiswing/dnd/motif_CopyNoDrop.gif" WIDTH="32" HEIGHT="32" ALT="Copy cursor icon for Linux/Solaris, the component below won't accept."></td><td>Copy.  The area underneath will not accept this data.</td></tr><tr><td align=center valign=center><IMG SRC="../../figures/uiswing/dnd/win32_MoveDrop.gif" WIDTH="16" HEIGHT="27" ALT="Move cursor icon for Windows, the component accepts the drop."></td><td align=center valign=center><IMG SRC="../../figures/uiswing/dnd/motif_MoveDrop.gif" WIDTH="32" HEIGHT="32" ALT="Move cursor icon for Linux/Solaris, the component accepts the drop."></td><td>Move.The component underneath accepts this type of data.</td></tr><tr><td align=center valign=center><IMG SRC="../../figures/uiswing/dnd/no.gif" WIDTH="20" HEIGHT="20" ALT="Move cursor icon for Windows, the component won't accept."></td><td align=center valign=center><IMG SRC="../../figures/uiswing/dnd/motif_MoveNoDrop.gif" WIDTH="32" HEIGHT="32" ALT="Move cursor icon for Linux/Solaris, the component won't accept."></td><td>Move.  The area underneath will not accept this data.</td></tr></table><p>On a <code>Component</code> supporting both Copy and Move,a normal drag from the component performs a move and a Control-dragperforms a copy.  The drag behavior from a native application toa Java application is platform dependent.  If only one of the operationsis supported, a normal drag performs that operation. For moreinformation on the behavior of the drop action, see the class spec for<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/dnd/DragSourceDragEvent.html">DragSourceDragEvent</a>.</blockquote><a name=intro><h2>Introduction to Data Transfer Support</h2></a><blockquote><p>The simple demo <code>BasicDnD</code> illustrates defaultdrag and drop behavior for several Swing components.At startup the components do not have drag turned on,but a check box allows you to enable dragging on the fly.Note that at startup, even though drag is not yet enabled,many of the components do support the cut/copy/paste of textusing key bindings.<p><center><a href="../../figures/uiswing/../../figures/uiswing/dnd/BasicDND.png" target="_top"><IMG SRC="../../figures/uiswing/../../figures/uiswing/dnd/BasicDND.png" WIDTH="500" HEIGHT="341" ALIGN="BOTTOM" ALT=""></a><br><em>This figure has been reduced to fit on the page. <br> Click the image to view it at its natural size.</em></center></p><blockquote><hr><strong>Try this:</strong>&nbsp;<ol><li> <a href="http://java.sun.com/docs/books/tutorialJWS/uiswing/misc/examples/BasicDnD.jnlp">Run     BasicDnD</a> using     <a href=http://java.sun.com/products/javawebstart>     Java<sup><font size=-2>TM</font></sup> Web Start</a>.     Or, to compile and run the example yourself,     consult the     <a href="examples/index.html#BasicDnD">example index</a>.<li> Select an item in the list, and then release the mouse button     so it is now highlighted.<li> Press the item again, this time holding down the mouse     button and begin to drag. Nothing happens because     <nobr><code>setDragEnabled(true)</code></nobr> has not yet been      called on the list.<li> Type Control-C.  This puts the text of the selected     list item onto the system clipboard.<li> Click in the text area.  The caret cursor blinks     showing that this component now has the focus.<li> Type Control-V.  The contents of the previously copied     text are pasted at the caret location.<li> Click the "Turn on Drag and Drop" check box.<li> Once again, press the selected item in the list

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -