This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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...
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.
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