java.lang.Object
javax.swing.TransferHandler
org.bzdev.swing.ReorderListTransferHandler
- All Implemented Interfaces:
Serializable
JList TransferHandler supporting reordering.
This transfer handler allows a JList to be reordered using
drag and drop operations. It does not allow D&D to be used
to add or remove elements from a list. One use case this transfer
handler supports is a component that contains a JList, a button
to add new entries to the JList and name them, and some additional
parameters. The use of this transfer handler then allows the JList
to be reordered conveniently.
Typically, a list using this transfer handler has a scroll pane
as a parent. In the following, we assume that the list contains
elements whose type is OurType
and that the class
OurType
has a toString()
method that will
produce a string whose length is the largest string length that should
appear in a JList for OurType
. The code is straightforward:
It is basically the default sequence of operations for enabling drag and drop for a JList.DefaultListModel<OurType> listModel = new DefaultListModel<OurType>(); JList<OurType> list = new JList<OurType>(listModel); JScrollPane scrollPane = new JScrollPane(list); TransferHandler th = new ReorderListTransferHandler(list); list.setPrototypeCellValue(new OurType(...)); list.setTranferHandler(th); list.setDragEnabled(true); list.setDropMode(DropMode.INSERT);
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.TransferHandler
TransferHandler.DropLocation, TransferHandler.TransferSupport
-
Field Summary
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canImport
(TransferHandler.TransferSupport support) protected Transferable
protected void
exportDone
(JComponent src, Transferable data, int action) int
boolean
importData
(JComponent comp, Transferable t) boolean
Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getVisualRepresentation, setDragImage, setDragImageOffset
-
Constructor Details
-
ReorderListTransferHandler
Constructor.- Parameters:
jlist
- a jlist using a DefaultListModel
-
-
Method Details
-
createTransferable
- Overrides:
createTransferable
in classTransferHandler
-
getSourceActions
- Overrides:
getSourceActions
in classTransferHandler
-
importData
- Overrides:
importData
in classTransferHandler
-
canImport
- Overrides:
canImport
in classTransferHandler
-
importData
- Overrides:
importData
in classTransferHandler
-
exportDone
- Overrides:
exportDone
in classTransferHandler
-