Solved

scrolling popup menu

Posted on 2002-04-06
9
817 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

696 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