In all major Java IDEs, there is a GUI designer.
When we select a component (A
Jbutton, for example) and move it to a
JFrame, how is it done?<br />
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...<br />
When one of those
JButton is dragged, some options of the action will be displayed.
I checked <a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/TransferHandler.html" rel="nofollow">
TransferHandler</a> but I don't know if it's the way to go. Is it?
It's certainly possible. You'll need to study the <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html" rel="nofollow"><em>Drag and Drop</em></a> tutorial. In particular, you may want to implement <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/droplocation.html" rel="nofollow"><em>Drop Location Rendering</em></a>, discussed <a href="https://forums.oracle.com/forums/thread.jspa?threadID=1350570" rel="nofollow">here</a>, to symbolize the action.
By encapsulating a button's name, icon, listener, etc. in an <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html" rel="nofollow">
Action</a> 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 <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/toolbar.html" rel="nofollow">
JToolBar</a>. In normal mode, clicking the button <em>evokes</em> the
Action; in editor mode , clicking the button <em>changes</em> the
Action, again via
setAction(), to one chosen from a list.