Skip to main content

Request for feedback: implementing Swing-based drawers

2 replies [Last post]
mspetrovic
Offline
Joined: 2003-06-10
Points: 0

Good day.

I've inherited some code to which I need to add a 'dresser drawer' like functionality. Click on a logical 'open' button and the drawer opens, revealing, or displaying as the case may be, a JPanel with more stuff in it. Click on a logical 'close' button and the drawer closes, leaving its container in the visual state in which it started. A familiar example of this effect might be something like the Mac Dock in 'auto hide' mode, where the Dock moves in and out of sight and addressability with some pointer action. The Dock is always 'there', but sometimes just not visible. So it would be with the drawer.

I am wondering if a solution would be based loosely on theDrawer.setVisible(), or whether something that sets the drawer's component width or height to 0 for-hide would be more likely.

Can anyone offer guidance on how to approach this using standard Swing techniques?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
javaguy44
Offline
Joined: 2006-07-06
Points: 0

Take a look at JXCollapsiblePane in swingx

or it's original component the JCollapsiblePane in l2fprod

HTH

invalidname
Offline
Joined: 2003-06-09
Points: 0

I actually banged on this for a week or so while working on [i]Swing Hacks[/i] before abandoning it as impractical, at least with my approach. What I thought to do was to have a JWindow (which is a top-level container but doesn't have the decorations of a JFrame or JDialog) that I would manually manage in relation to the JFrame that it seemed to come "out" of. What burned me was a lack of Z-order controllability -- with focus on the window, it would then be above the JFrame, potentially cutting off the side of its frame (particularly bad if you want to animate the "slide out"). I also found it impractical to move the child window with the parent frame... listening for changes to the parent's bounds, some JVM's and OS's would give me continuous events during a move or resize, others wouldn't. Without continuous updates, moving the frame would basically detach it from the drawer until the move was complete, at which point the drawer would get one resize event and snap into position. I came to believe I couldn't come up with something that wouldn't a) take 10 pages of hacky-ass code in the book, and b) suck anyways. And we were on a tough schedule, so I cut it.