Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

looking for help on Swing DND (unsupported JComponents)  RSS feed

 
Geronimo M. Hernandez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I working on a kind of visual composer, where I can drag & drop gui-elements from one pane to the other (and I'd like to support several drop locations).
I'm not looking for a mouse-handler, that handles just the moving of the elements.

The target pane is divided into regions and a component will be added to a region, letting the LayoutManager do the final positioning.

I added a subclass of a TransferHandler to JPanel and use canImport() together with the JPanel to calculate and show the region.
The prototype for visualization of the regions works fine for empty panes.

The problems start with populated panes. As my components are not static - like on most GUI-editors, but connected with real data (even during drag), I don't want to disable their dnd support. But when I move a new component over a i.e. JTextField already attached to the "DropPane", the JTextField responds to the TransferHandler and I'm not able to show the dropping region any more.

So how can I get the response of my "DropPane" even if the drag-component is above an attached JComponent with initial drag support?

My problem is, I didn't find any information about usage of the classes from java.awt.dnd (and yes, I know the dnd tutorial).
I already scratched some of the java sources, but I did not find a way to proceed.

Do I have to iterate all children of my "DropPane" to disable them during active dnd and if so, how can I determine the "DropPane" of the drop intention if I have multiple in the same TopWindow?
Or is there another way preventing existing drop-sources to respond to my TransferHandler?

//Edit:
I tried to iterate over all children to disable them - that makes no difference.
As a sample, I filled a 4x5 grid alternating with JLabel and JTextfield - being the JLabel the DragSource and the JPanel the DragTarget (both with listeners). When I use StringSelection as Transferable, dropping into JTextfield works.
When I use a DataHandler as Transferable, JTextfield denies the drop, but is stil active, no matter whether I use setEditable(false), or
setEnabled(false). On dragging over a JTextfield a dragExit() occurs.
The JLabel is transparent, so if I drag a JLable over another JLabel, the JPane is responding to the drop action.

How can I achieve something similar for JTextfield and others with buildin drop support?

Any hint is appreciated.

kind regards

Geronimo
 
Brian Cole
Author
Ranch Hand
Posts: 937
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geronimo M. Hernandez wrote:I working on a kind of visual composer, where I can drag & drop gui-elements from one pane to the other (and I'd like to support several drop locations).

...

The problems start with populated panes. As my components are not static - like on most GUI-editors, but connected with real data (even during drag), I don't want to disable their dnd support. But when I move a new component over a i.e. JTextField already attached to the "DropPane", the JTextField responds to the TransferHandler and I'm not able to show the dropping region any more.

So how can I get the response of my "DropPane" even if the drag-component is above an attached JComponent with initial drag support?


If you don't want the existing components to react to drops, you could try an approach where the dropping is onto some kind of glass pane. I've never tried it, though.
 
Geronimo M. Hernandez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

thank you for your attention!

Brian Cole wrote:If you don't want the existing components to react to drops, you could try an approach where the dropping is onto some kind of glass pane. I've never tried it, though.


Yep, thought about that.

The problem is, that then I have to tie the glaspane and the JPanel together - which I don't really want.
You can download my prototype from http://www.gmx.de/mc/DanhrBrPDdUfmw3o7PMWWObqg23LLE
The link is a temporary link, that is valid until 16.04.2009

I like to have arbitrary components in the root window, where a Droptarget-JPanel is one of them. I also want to be able to have several Droptarget-JPanels in a root window and I don't like the glaspane limit any design decisions.

With my prototype, I reached half of the behavior, I'd like, by using intentionally wrong code.
It was really surprising, that with the wrong code, the JTextFields are transparent - and I found no way to get the same result with correct code.
Even with throwing the same exception I did not succeed.
The latter is, the JTextfields are unable to receive their own drag transfers.

I'm actually digging into Component from awt. May be I'll find the place, where to insert my dnd-flow.
Currently I don't have the picture, how things play together. Can somebody explain me, how dnd works without using a TransferHandler?
I know, that DragSource and DropTarget play together with their listeners, but I guess, there must be a master behind the scenes.
Who decides, which component to ask to accept the dragged transfer content?

kind regards

Geronimo
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!