aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Implementing drag in custom layout manager Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Implementing drag in custom layout manager" Watch "Implementing drag in custom layout manager" New topic
Author

Implementing drag in custom layout manager

Carvel Baus
Greenhorn

Joined: Jan 15, 2009
Posts: 8
I have implemented a custom layout manager to create an accordion panel (like in Outlook, visio, entourage, etc.) The basic behavior is each time I click a divider, it opens or closes the respective panel below the divider. All this was done by extending the LayoutManager class (not LayoutManager2) and a little bit of special behavior.

What I need to do now is be able to grab a divider and drag up or down, to resize the view of panel . I don't see this being drag and drop (using a TransferHandler) as the view must update with each pixel move.

I have read some about drag gestures, etc but am not sure which way I should be looking . Can someone provide some guidance as to what methods I should be looking at to make this happen and the best way to propagate the event to the layout manager so that it is the one doing the work of the update, as it should be? Should I be looking at Drag gestures, mouse moves, etc...

Thank you for your suggestions.
Francois Nadeau
Ranch Hand

Joined: Apr 09, 2009
Posts: 46
Hello Carvel,

Drag and drop is a rather hairy and ugly beast in Java. However, before diving into it, why don't you place a JSplitPane between each of the sections? Or I suppose you can add a mouse drag listener to your divider component, and then change the components Y location based on where the mouse moves.

BTW, if you are creating this for a commercial product then I would suggest looking into SwingLab's JXTaskPanes (OpenSource). I have used this component before, and find it to be professional and easy to use.

You can see a web-start demo on this link: http://swinglabs.org/demos.jsp (SwingX Demo).

Cheers.


[url]http://FrancoisNadeau.com[/url]
Carvel Baus
Greenhorn

Joined: Jan 15, 2009
Posts: 8
Francois,

Thank you for your input. I actually created this accordion panel because the JSplitPane was so difficult to work with where one would need more than 2 or 3 split panels. Using a custom layout manager, I allow the user to add as many jpanels as they like, each having a header and being able to hide/show and hopefully soon, resize by dragging.

It turns out that what I need is to implement the MouseMotionListener interface and then have the layout manager respond appropriately to each event as it occurs. The most challenging piece of it is figuring out which things need to move when one is getting resized. A straight-forward problem but not so obvious a solution - trial and error are my friend

thanks again for your input.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing drag in custom layout manager