954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Java GUI--Dynamically Adding Buttons to a Menu

Hi All--
I basically am trying to write a piece a piece of code for an application that will list all the open frames in the program, and if you click one, it is selected and brought to the top of the program. I have a menu bar, and I want to be able to select a Menu from it, and then have that menu drop down and list all the open frames.
The problem is I have to gather the open frames whenever I click the menu, and so I have to dynamically create buttons, corresponding to an arbitrary amount of frames which might be open.
Getting a list of the components is not difficult, and creating buttons doesn't seem to be. I just go through a for loop of all the open components, creating buttons, within a mouse listener. But it won't let me insert these buttons into the menu unless the menu is final (which it can't be since it should be dynamic).

Any ideas?

Thanks,
Miles

miles11
Newbie Poster
1 post since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

You should be able to easily do this with add() or remove(). Are you remembering that a Menu must have JMenuItems and not buttons? Also, if your getting an error, post it.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

use jbuilder, i am a newer,readed some paper,i think jbuilder is a basic for who want the gui design.

flybet
Newbie Poster
1 post since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You