This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes opening a frame on click on JMenuItem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "opening a frame on click on JMenuItem" Watch "opening a frame on click on JMenuItem" New topic
Author

opening a frame on click on JMenuItem

pankaj saxena
Ranch Hand

Joined: Nov 21, 2009
Posts: 46
Ques:
i have two menuitems : 1. Fill the form and 2. search the records.
Problem: i can't open the form when i click on 'Fill the form' menuitem, under the same MenuBar frame.

same problem is with second menuitem.

please provide me some links or your suggestions to solve this.

regards,
pankaj.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3067
    
  33

If you want to show multiple frames you would have to use- JDesktopPane and then for each action you can hide/show corresponding JInternalFrame. You can have one Internal Frame for each of your form. I have used this a lot for my projects.
Or
You can have one JFrame and then keep changing the contents of the frame based on the Events- May be you can use one JPanel for each event- One JPanel for Fill form UI, then one JPanel for searching the records UI.

If you have some working code where you are finding problem- You can post it here. Also keep the code simple and post a working code.

Mohamed Sanaulla | My Blog
pankaj saxena
Ranch Hand

Joined: Nov 21, 2009
Posts: 46
sir,
i don't have to use Internal frames, because i want to use normal JFrame.
But, if you are saying that I have to add Internal frame to JDesktopPane , so my question is , can i add a frame to JDesktopPane? so that i can open a frame on the click of a menuitem under the same Menubar.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

It's better to use a modal JDialog.


luck, db
There are no new questions, but there may be new answers.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3067
    
  33

pankaj saxena wrote:sir,
i don't have to use Internal frames, because i want to use normal JFrame.
But, if you are saying that I have to add Internal frame to JDesktopPane , so my question is , can i add a frame to JDesktopPane? so that i can open a frame on the click of a menuitem under the same Menubar.


Is it a requirement that you have to use JFrame only? You can't add a Window (JFrame) to a container (JDesktopPane). But you can add JInternalFrame to JDesktopPane. You actually have a JFrame which contains JDesktopPane and this in turn contains multiple JInternalFrame.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

Since you have two menu items, it implies you already have an existing JFrame which is visible on the screen. How have you added the actions to your menu items? Once you get the actions correct you can opt to open a new frame, use dialogs or even switch the current frame contents.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: opening a frame on click on JMenuItem
 
Similar Threads
MenuItem eventhandling
prob in going from 1 panel to another
Urgent - pls help
AppletContext.showDocument()
To disable the frame .........................