Sunday, March 27, 2011

How to create a scrollable JPopupMenu

I am trying to create a JPopupMenu that has a scrollbar so that I can display a large number of items.

There are a couple of implementations on the web that all have problems:

  1. http://forums.sun.com/thread.jspa?threadID=5128630

    Looks correct (except for issues with separators) but if you scroll it the highlighting and selection no longer work.

  2. http://www.beginner-java-tutorial.com/scrollable-jpopupmenu.html

    Does not look like a JPopupMenu (no L&F background or highlighting) but works except for the fact you can't put JMenuItems in it - instead you have to use some hacked button.

Can anyone point me to a working solution before I try and debug either of these or write my own?

From stackoverflow
  • My suggestion would be to not use a popup menu if it is that big.

    Most of the current OS user guidelines would suggest this as well. A menu that big is going to be a nightmare for the user to find something in if they need to scroll, isn't it?

    Howabout a popup window/dialog with a filterable list instead?

    (for example, the CTRL+O popup filterable tree in eclipse, or the CTRL+Space Content Assist list in eclipse)

    Tom : Agreed - Jason, a scrolling popup menu would make for a poor user experience - makes me swear every time I hit one of those country popups and they've enumerated every single country.
  • I agree with John Gardner, you should be using a dialog. We have used the swingx filterable components, they are very good for filtering...

0 comments:

Post a Comment