This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Sliding Panels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Sliding Panels" Watch "Sliding Panels" New topic

Sliding Panels

Steve Knight

Joined: Jun 19, 2001
Posts: 11
Does anyone know how to implement a panel that slides out from the side of a frame when you click a button or something. I want something similar to how IntelliJ's IDEA does it (for those that know IDEA).
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Just make a panel with 2 sides (BorderLayout.EAST and BorderLayout.WEST) and call setVisible( false ) on the component on the side that you want to toggle. Then, put a JButton( or JLabel ) on the other side and add a mouse ( or action ) listener to it to call setVisible( true ) on the component that is hidden.

The one thing that I found was tricky was hiding the component again after the mouse left the area. I tried adding a mouselistener and using mouseExited(), but the exit event doesn't always get thrown ( This may be due to the fact that the component that I was toggling was a drag source for Drag and drop events... this may have interfered with the normal mouse listener... ), so I had to add a mouse listener to the component containing the top panel... this ended up being the content pane of the JFrame everything was in... and testing for the state of the panels and the location of the mouse...


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Steve Knight

Joined: Jun 19, 2001
Posts: 11
Doh! So simple.
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
I don't know if it fits your scenario, but you could also use a JSplitPane which gives you the option to collapse and reopen each side of the pane. JSplitPanes can be vertical or horizontal and have a bunch of other options as well.
Just a thought.

Wait a minute, I'm trying to think of something clever to say...<p>Joel
I agree. Here's the link:
subject: Sliding Panels
Similar Threads
How to get project ?
why should I avoid autoboxing
Head First Java problem
JTA - what actions can be managed by transaction?
Nested components in <h:selectOneRadio>