I'm doing a drag and drop of custom objects into JLabels and am able to reference the object during the transfer process (change label String to received object toString), but unsure of how to actually store the custom object in the JLabel or build a reference.
What is the best way to accomplish this during the transfer process?
Here is the working transfer code that receives the object and uses it to set text (much thanks to a previous answer: here:
public boolean importData(TransferSupport support) {
boolean accept = false;
if (canImport(support)) {
try {
Transferable t = support.getTransferable();
Object value = t.getTransferData(PersonTransferable.PERSON_FLAVOR);
if (value instanceof Person) {
Component component = support.getComponent();
if (component instanceof JLabel) {
((JLabel)component).setText(((Person)value).toString());
//action here
}
}
} catch (Exception exp) {
exp.printStackTrace();
}
}
return accept;
}
The JLabels have specific instance variables that I'd like to store them to. Since I have the component (JLabel) and value (custom object), can I make this link?
Worst case scenario, I just have to build a TransferHandler for each label and reference the value exactly. Is this maybe best practice anyways?