Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sliding Panels

 
Steve Knight
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
Thanks,
Steve
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

-Nate
 
Steve Knight
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh! So simple.
Thanks,
Steve
 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic