I searched on the internet for examples how to Drag and Drop JButtons to an Object but I could not make it work.
What my program does, is that when I click on a button, the selected object gets a new value. I want to be able to do this not by clicking, but by dragging the JButton.
How can I do this ? I found this, and I tried to put in my code:
button = new JButton(new ImageIcon(newimg));
button.setTransferHandler(new TransferHandler(/* what should I write here? */));
button.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e) {
JComponent c = (JComponent)e.getSource(); // what is this c ?
TransferHandler handler = c.getTransferHandler();
button.exportAsDrag(c, e, TransferHandler.COPY); // what that does and what should I add more?
}
Aucun commentaire:
Enregistrer un commentaire