views:

186

answers:

1

I'd like to show increasingly more of a JPopupMenu so it appears to "slide out". It's not for menu items, where animation doesn't make too much sense. Instead it's for a panel with some real components (oh yeah, you can add any JComponent to JPopupMenu).

JPopupMenu has many private fields and methods, which makes it hard to extend. Plus I'm not familiar with Swing animation to begin with.

Thanks a lot for your help!

A: 

I just did this within the last few weeks. I went a slightly different approach, and Grabbed the layeredPane, and then added a Custom JPanel to the layered pane. In the jpanel i overrode the getHeight method, and had the height start at 0. I could then add whatever components I wanted to my jpanel. In the jpanel I had a method to start animation, this started a timer, and in the timer all I did was increase the height of my jpanel to a max size.

That's it. It works really well in my application, I have it tied to expand below a Jbutton on press, and collapse on another press.

One more thing, you'll want to add a mouseAdapther to the jpanel so events don't go through the components below the layer.

broschb
Thanks! I still want to put the JPanel into JPopupMenu so Swing handles the popup correctly. So I take your idea to set JPanel's height and it works.
Geoffrey Zheng