Solved

scrolling popup menu

Posted on 2002-04-06
9
812 Views
Last Modified: 2008-03-10
Hi,
I'm using a "dynamic" JPopupMenu, (which mean that I add/remov MenuItem from the popup according to the user selection). As a result, if I have many MenuItem the popup menu gets cut so the user can’t see all the JMenuItem.
How can I present the popup with scrolling and set the max size of the popup?

Thanks,
Shushan
0
Comment
Question by:Shushan
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 6924785
I don't unbderstand exactly what you meen by "As a result, if I have many MenuItem the popup menu gets cut so the user can't see all the JMenuItem" but you can do the following :

Instead of adding/removing directly from the popup menu, you should keepthe content of it in a separate class, and recreate the popup with the desired content every time.

Supose you have a class PopupContentManager, like this :

public class PopupContentManager {
  private Vector popupItems;
  ......................
  public void addItem(JMenuItem item) {
    popupItems.addElement(item);
  }
  public void removeItem(JMenuItem item) {
    popupItems.removeElement(item);
  }

  public void showPopup(int x, int y) {
    JPopupMenu popup = new JPopupMenu();
    for(int i= 0; i<popupItems.size(); i++)
      popup.add((JMenuItem) popupItems.elementAt(i));
    popup.show(x, y)
  }
}
0
 

Author Comment

by:Shushan
ID: 6924811
My problem is with the display of the menu when I have many items in it (and not with the fact that it is a dynamic menu – I know how to add/remove menuItems to/from the popup). When I have many JmenuItem in the menu so that the height of the menu is bigger then the screen, the user can't see some of the JMenuItems.
What I need is a way to put the menu in a scroll pane.

thanks, Shushan
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6924821
One solution is to put the menu like they do in a Java source editor for autocompletion, using JWindow. Instead of showing directly the popup you should show a JWindow containing a scrollPane with the desired popup. You must take care at this solution about the state of the JWindow, e.g. if was hidded by the application window you should destroy'it.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Expert Comment

by:Ovi
ID: 6924830
Another solution with graphical effect is to implement something like windows 2000 or 98 menus. You can create a special JMenuItem containing a down arrow/up arrow, which if pressed should hide/show the contents of the popup from the index 0 to his current index. To not destroy the JMenuItems you can create special menuItems which have the hidden state (or directly using their setVisible(true/false) method).

For the "arrow menu item" you can set the text to "\/" or "/\" to simulate the arrow, or write a custom JMenuItemUI class in which you actually draw a arrow. This class should have a refference tor the menu from which is part of.
0
 
LVL 9

Accepted Solution

by:
Ovi earned 80 total points
ID: 6924834
Sorry, not JMenuItemUI but MenuItemUI.
0
 

Author Comment

by:Shushan
ID: 6924842
thanks, i'll try it.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6924870
me too and good luck.
0
 

Author Comment

by:Shushan
ID: 6924872
thanks, i'll try it.
0
 

Author Comment

by:Shushan
ID: 6924879
thanks, i'll try it.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where to store the queries for modification of table 4 62
Java Timer (static) 9 44
Apps blocked by Java 9 79
hibernate insert example 13 29
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question