Skip to main content

help with integrating scrollpane and menuitems - jana

4 replies [Last post]
javaprog
Offline
Joined: 2004-01-30

There was a post by Jana on 7th July '03 "JPopupMenu in a ScrollPane". I want to do the exact same thing. The original post is here:

http://www.javadesktop.org/forums/thread.jspa?messageID=1590

I have several menuitems and specific action listeners for the menuitems. Right now, there are over 30 menuitems and I want to implement scrolling capability. I do not want to do the JList implementation because that would involve a lot more changes to the code. I have tried to implement this functionality (similar to zander's solution code in the post) but the whole list disappears as soon as I move the mouse cursor over it.

Jana, can you please tell me how you finally solved this. If anyone else can post their ideas, then that would be highly appreciated.

Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
viravan
Offline
Joined: 2003-06-23

For a scrollable popupmenu, see:

http://forum.java.sun.com/thread.jsp?forum=57&thread=483165

;o)

V.V.

javaprog
Offline
Joined: 2004-01-30

Thanks viravan for your response. However, to use your solution for adding menuitems would involve a lot of changes at my end. I prefer not to make those changes but if there is no alternative, then I will have to!

Viravan, could you please look at the code snippet provided at

http://www.javadesktop.org/forums/thread.jspa?messageID=1590

and determine why the list disappears as soon as I move my mouse cursor. Is there any way that I can make scrollbar work with JPopupMenu and menuitems without having to use ComboBoxUI.

Your help is highly appreciated.

Thanks

viravan
Offline
Joined: 2003-06-23

>However, to use your solution for adding menuitems would involve a lot of changes at my end

Why? You can create a scrollable popup by providing an array of objects, a vector or a combobox model!

>Viravan, could you please look at the code snippet provided at

If you're referring to Zander's snippet, if he said he couldn't get it to work, I am sure it's not for lack of trying.

;o)

V.V.

javaprog
Offline
Joined: 2004-01-30

I am a novice when it comes to UI programming, so please bear with me.. I tried passing an array of JMenuItems to ScrollablePopupMenu. Each of the JMenuItems have been assigned a different text "Text1", "Text2", and so forth. However, the display I get on the screen is the whole thing..
javax.swing.JMenuItem [,0,0,0x0,invalid,alignmentX=null,alignmentY=null,border=javax.s ...., text=Text1]

How can I make it to just display the text I assigned and not the object properties?

Also, I have assigned different action commands to each of the JMenuItems, for eg., "Text1Selected" for the first JMenuItem, etc. In the actionPerformed method, getActionCommand() always returns "comboBoxChanged" as expected.. how can i listen for the specific actions involved with each of the JMenuItems?

Thanks a lot for your help.