Update / Status: An error has been reported in Oracle and is currently still open / not resolved: https://bugs.openjdk.java.net/browse/JDK-8054325 p>
I found a strange error that only appears on Java 7 and 8 on OS X, not Java 6, nor Java 7 Windows.
Below is the extracted error, removing as much unnecessary code as possible. This leaves us with a small table and a button, where we can drag a cell from the table on top of the button.
In our production code, we use TransferHandler , which has COPY_OR_MOVE as the source action. We have two goals, one DropTarget accepts as MOVE , the other accepts as COPY . It looks like the JDK / JRE is broken in OS X because if DropTarget accepts as COPY , then the reports in TranferHandler were MOVE .
If we execute the code below in Java 6 (or Java 7 on Windows), it reports ( as expected ):
not move is copy
But when we run it in OS X Java 7 or Java 8, we get the following:
is move not copy
I tested and reported this to Oracle (error report has not yet been completed). But since it will take (loooong) until it is fixed, maybe someone has an idea on how to make a βcleanβ workaround?
I would prefer that the target of the binding is not tied to the original component, telling it the actual action (copy or move), this sound is too complicated.
import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.dnd.DnDConstants; import java.awt.dnd.DropTarget; import java.awt.dnd.DropTargetAdapter; import java.awt.dnd.DropTargetDropEvent; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.TransferHandler; import javax.swing.table.DefaultTableModel; public class DropExample extends JPanel { public static void main(final String[] args) { final JFrame frame = new JFrame(); frame.setSize(200, 100); frame.add(new DropExample()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public DropExample() { add(createTable()); final JButton button = new JButton("Drop here"); button.setDropTarget(new DropTarget(button, new DropTargetAdapter() { @Override public void drop(final DropTargetDropEvent dtde) {
java java-7 drag-and-drop macos
Roy van Rijn
source share