Solved

scrolling popup menu

Posted on 2002-04-06
9
813 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
map related example 6 55
eclipse console opening separately 2 29
Notify sent to other threads in Java 9 33
Java class and jar 3 21
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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

840 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