Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a scrollable JPopupMenu

Tags:

java

swing

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?


2 Answers

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)

like image 167
John Gardner Avatar answered Nov 26 '25 20:11

John Gardner


I agree with John Gardner, you should be using a dialog. We have used the swingx filterable components, they are very good for filtering...

like image 42
Daniel Hiller Avatar answered Nov 26 '25 21:11

Daniel Hiller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!