Reputation: 2070
In all major Java IDEs, there is a GUI designer.
When we select a component (A Jbutton
, for example) and move it to a JPanel
or JFrame
, how is it done?
Is it a copy of the dragged component that is created on the other container?
On a project I'm working on, I have some JButton
I would like to be able to drag to a panel. Theses JButton
represent some actions, like "copy file", "move file", etc...
When one of those JButton
is dragged, some options of the action will be displayed.
I checked TransferHandler
but I don't know if it's the way to go. Is it?
Upvotes: 1
Views: 89
Reputation: 205775
It's certainly possible. You'll need to study the Drag and Drop tutorial. In particular, you may want to implement Drop Location Rendering, discussed here, to symbolize the action.
By encapsulating a button's name, icon, listener, etc. in an Action
instance, your importData()
implementation can easily use setAction()
to change the target button's behavior dynamically.
An alternative approach might be to add your buttons to a JToolBar
. In normal mode, clicking the button evokes the Action
; in editor mode , clicking the button changes the Action
, again via setAction()
, to one chosen from a list.
Upvotes: 3