This can be done by changing the TransferHandler JTree to return null Transferable to non-leaf nodes.
Here is a quick example:
JTree tree = new JTree(); tree.setDragEnabled(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setTransferHandler(new TransferHandler(null) { public int getSourceActions(JComponent c) { return MOVE; } protected Transferable createTransferable(JComponent c) { JTree tree = (JTree) c; DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent(); if (node.isLeaf()) {
Emmanuel bourg
source share